28.8bps Modem
Prophet
Also, bitwise operators are used for sawing bits off larger numbers.
For (a contrived) example, lets say you had a counter that incremented every second:
If you wanted an event to happen say, every 16 seconds you can say:
The bitwise and operator will give you the the bits of the larger number specified by the mask (0xf), in this case the bottom 4 bits. (0xf in hex = 15 in decimal = 1111 in binary.)
For (a contrived) example, lets say you had a counter that incremented every second:
Code:
int counter;
If you wanted an event to happen say, every 16 seconds you can say:
Code:
if ((counter & 0xf) == 0)
do_event();
The bitwise and operator will give you the the bits of the larger number specified by the mask (0xf), in this case the bottom 4 bits. (0xf in hex = 15 in decimal = 1111 in binary.)