Bitwise operators

closed account (EwCjE3v7)
Exercise:
What is the value of ¬'q' << 6 on a machine with 32-bit ints and 8 bit chars, that used Latin-1 character set in which 'q' has the but parrten 01110001


I think it would be 00000000 00000000 01000111 10000000
..........................................................................^.................^
Last edited on
You've shifted too far. It would be:
00000000 00000000 00100011 11000000 (or 0x000023C0)
Last edited on
closed account (EwCjE3v7)
Oh yes had one more, thank you for the quick reply. I don`t really understand hexidecimal, could you show me how they are used?
Last edited on
A group of 8 bits is represented by 2 hexidecimal numbers:

1
2
3
4
5
6
7
8
0000 0001 = 0x01
0000 0010 = 0x02
0000 0100 = 0x04
0000 1000 = 0x08
0001 0000 = 0x10
0010 0000 = 0x20
0100 0000 = 0x40
1000 0000 = 0x80


Then you can make combinations. If you wants two bits put togeather, just add the numbers:
1
2
0000 0011 = 0x03
0011 0011 = 0x33


So when I said 0x000023C0 I did this:
1
2
0000 0000    0000 0000    0010 0011    1100 0000
 0    0       0    0       2    3       C    0


For a short-cut memorize this table:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0x0 = 0000
0x1 = 0001
0x2 = 0010
0x3 = 0011
0x4 = 0100
0x5 = 0101
0x6 = 0110
0x7 = 0111
0x8 = 1000
0x9 = 1001
0xA = 1010
0xB = 1011
0xC = 1100
0xD = 1101
0xE = 1110
0xF = 1111


I usually need to think about 0xB and 0xD. Those are the ones I haven't memorized.
closed account (EwCjE3v7)
Thank you sorry for the late reply
Topic archived. No new replies allowed.