🔸Bit Manipulation
Last updated
Last updated
bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word.
tasks that require bit manipulation:
low-level device control
error detection
correction algorithms
data compression
encryption
algorithms optimization
each position value in a binary number are the powers of two
1 byte = 8 bits
0 is off, 1 is on
the rightmost bit of a byte is known as the least significant or low-order bit, the leftmost bit is known as the most significant or high-order bit
changing a bit to 1 is called setting a bit changing a bit to 0 is called resetting a bit
the representation of negative number:
a way to convert negative numbers from decimal to binary is to first add 1 to the value express the absolute value of the result in binary complement all the bits change all the 1s to 0s and 0s to 1s
example:
example:
example:
if you see the error about pow() in IDE You need to link with the math library:
The error you are seeing: error: ld returned 1 exit status is from the linker ld (part of gcc that combines the object files) because it is unable to find where the function pow is defined.
Including math.h brings in the declaration of the various functions and not their definition. The def is present in the math library libm.a. You need to link your program with this library so that the calls to functions like pow() are resolved.