Using bit manipulation in a very high level language?!

by shian ⌂, Saturday, August 15, 2020, 07:27 (45 days ago) @ shian

Euphoria 3 is a very high level language, it does not use low level tricks, it lets you program safely, without worrying about low level issues.

Yet Euphoria 3 allows you to perform low level operations when needed (when you want to access C shared library - .DLL/.so, DOS interrupt, i386 machine language, or just for extremely fast code).

In Lib2 library I'm using low level functions for manipulating bits, such as and_bits(), or_bits(), etc, since a library routine must be fast and efficient as possible. A library routine is a basic building block which should be suitable for many uses.

In your program you are not forced to use low level functions. Euphoria 3 offers high level functions for manipulating bits safely (shift bits, rotate bits, slice bits, etc), these functions are: int_to_bits(), bits_to_int().

Although these are high level bit manipulation functions, they are extremely convenient, very safe, and... very fast, since in Euphoria 3 integer calculations are very fast. I recommend you to use these functions (unless you need some extremely fast operations from Lib2 library). I personally used these functions a lot, that's why I can recommend them.

Conclusion: In Euphoria 3 you can use high level functions for manipulating low level bits, using the functions int_to_bits(), bits_to_int() and also bytes_to_int() and int_to_bytes(). See "Operations on sequences" in the Reference Manual (refman.doc).

Tags:
bit, bits


Complete thread:

 RSS Feed of thread

powered by my little forum