embedded - understanding bit shifting in registers -
i have update 32 bit register using these data includes bit shifting, confused 2 things:
- which lsb , msb,
- what operator
|
given expression:
3 << 0 | 7 << 3 | 1 << 6 | 0 << 7 | 1 << 7 | 0 << 8 | 0 << 10 | 0 << 11 | 0 << 12 | 0 << 13 | 0 << 14
and remaining 15 bits 0
.
how data shifted, assuming initial bits in register 0's?
011 111 1 0 1 0 0 0 0 0 0 x.......x
or
x .....x 0 0 0 0 0 0 1 0 1 111 011
the lsb (least-significant bit) bit value represents 1 (2^0) , msb bit value represents 2^(n-1), n number of bits in register. in general, when written out in binary, msb left-most bit , lsb right-most bit. more not, lsb shown bit 0 in hardware documentation, though know 1 company reverses bit numbering msb numbered 0.
<<
c shift-left operator, shifting bit away lsb , toward msb. therefore 7<<3
represents 111000
in binary.
|
c bit-wise or operator. used combine values resulting bits 1 if either of corresponding input bits one.
looking @ original value 3 << 0 | 7 << 3 | 1 << 6 | 0 << 7 | 1 << 7 | 0 << 8 | 0 << 10 | 0 << 11| 0 << 12 | 0 << 13 | 0 << 14
0000 0000 0000 0011
3<<0
0000 0000 0011 1000
7<<3
0000 0000 0100 0000
1<<6
0000 0000 0000 0000
0<<7
etc.
this type of construct typically used describe value going register noting individual fields of register.
Comments
Post a Comment