Bit Manipulation And Bitwise Flashcards
Bit manipulation
Modifying individual bits within an object, used for encription and compression algorithm
Bit flags
Bits when individual bits of an object are used as boolean values
A flag
In computing, a value that acts as a signal for some function or process
Defining a set of bit flags
Using unsigned integer of the apropriatesize depending on how many flags we have or std::bitset
Bit numbering
In a sequence we number the bits from right to left starting with 0, each number denotes bit position
Functions that are useful for bit manipulation
Std::bitset provides 4
- test()
- set()
- reset()
- flip()
Test()
Allows us to qmuery whether a bit is a 0 or 1
Set()
Allows us to turn a bit on
Reset()
Allows us to turn a bit off
Flip()
Allows us to flip a bit value from 0 to 1 and vice versa
Bitwise operators
Bot manipulation operators
<>,~,&,| and ^
Bitwise left shift
Shifts bits to the lef, lefto operand is the expression to shift the bits of, right operand is integer number of bits to shift left by x«1, new bits recieve value 0
Bitwise right shift»_space;
Shifts bits to the right
Operators «_space;and»_space;
Are used for output and input
Overloaded
Provided an alternative definition for operator