unsigned char x1, x2, x3, x4;
unsigned long int xx;
x4 = xx & 0x3F;
x3 = xx >> 6;
x2 = xx >> 14;
x1 = xx >> 22
2.
A= 0x4B2F;
A1= 00000000;
A2= 00000001;
A3= 00101100;
A4 =10111100;
If 0x00 is added to LSB then it becomes 0x4B2F00
and to make it 32 bits if you add another 0x00 to MSB it becomes 0x004B2F00 which is same as 0x4B2F00.
So,
A1 = 0x00 = 0b00000000
A2 = 0x2F = 0b00101111
A3 = 0x4B = 0b01001011
A4 = 0x00 = 0b00000000
unsigned char A1, A2, A3, A4
unsigned long int y = 0x4B2F;
y <<= 8;
A1 = y;
A2 = y >> 8;
A3 = y >> 16;
A4 = y >> 24;
Oops. I got it wrong.
Here how it should be done
unsigned char A1, A2, A3, A4
unsigned long int y = 0x4B2F;
y <<= 2;
A4 = y;
A3 = y >> 8;
A2 = y >> 16;
A1 = y >> 24;
- - - Updated - - -
Try this. This might not work for all values.
Code C - [expand] |
1
2
3
4
5
6
7
8
9
| unsigned char A1, A2, A3, A4
unsigned long int y = 0x4B2F;
y <<= 2;
A4 = y;
A3 = (y >> 8);
A2 = (y >> 16);
A1 = (y >> 24); |