Byte shifting
Introduction
Shifting or byte shifting is a process of shifting bytes of a given binary number in ether left or right direction. In programming shifting is marked by the shift operator:
- Right shifting, decalage a droite
>> - Left shifting, decalage a gauche
<<
EXEMPLE
Consider the octet / byte :
00111000
00111100 >> 1->00011110
00111100 << 1->01111000
In this exemple we shifted the binary
00111100by one bit in both left and right direction.
DANGER
Arithmetic and byte shifting
In a given base b, where b represent the number of symbol used to count. shifting by n is equivalent to multiply by .
Formula :
It’s more striking in binary as with the naked eye, we can observe this formula.
| Decimal | Binary |
|---|---|
| 1 | 1 |
| 2 | 10 |
| 4 | 100 |
| 7 | 111 |
| 14 | 1110 |
| 28 | 11100 |
NOTE
Multiplying by 2 is the same as shifting by left by one