Book Section 2.1.
Rather than accessing individual bits in memory, most computers use blocks of 8 bits, or bytes, as the smallest addressable unit of memory. A machine-level program views memory as a very large array of bytes, referred to as virtual memory. Every byte of memory is identified by a unique number, known as its address, and the set of all possible addresses is known as the virtual address space. As indicated by its name, this virtual address space is just a conceptual image presented to the machine-level program. The actual implementation is by use of combination of dynamic random access memory (DRAM).
Hexadecimal Notation:
A single byte consists of 8 bits. In binary notation, its value ranges from 000000002 to 111111112. When viewed as a decimal integer, its value ranges from 010 to 25510. Hexadecimal (or simply “hex”) uses digits ‘0’ through ‘9’ along with characters ‘A’ through ‘F’ to represent 16 possible values. Written in hexadecimal, the value of a single byte can range from 0016 to FF16. In C, numeric constants starting with 0x or 0X are interpreted as being in hexadecimal. The characters ‘A’ through ‘F’ may be written in either upper- or lowercase. For example, we could write the number FA1D37B16 as 0xFA1D37B, as 0xfa1d37b, or even mixing upper- and lowercase (e.g., 0xFa1D37b).
Conversion between Different Number Systems:
Decimal | Hexa-Decimal | Binary |
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 2 | 0010 |
3 | 3 | 0011 |
4 | 4 | 0100 |
5 | 5 | 0101 |
6 | 6 | 0110 |
7 | 7 | 0111 |
8 | 8 | 1000 |
9 | 9 | 1001 |
10 | A | 1010 |
11 | B | 1011 |
12 | C | 1100 |
13 | D | 1101 |
14 | E | 1110 |
15 | F | 1111 |
Exercise, book 2.1:
Perform the following number conversions:
- 0x25B9D2 to binary
- binary 1010111001001001 to hexadecimal
- 0xA8B3D to binary
- binary 1100100010110110010110 to hexadecimal
Exercise, Book 2.2:
n | 2n (Decimal) | 2n (Hexadecimal) |
5 | 32 | 0x20 |
23 | 8388608 | 0x800000 |
15 | 32768 | 0x8000 |
13 | 8192 | 0x2000 |
12 | 4096 | 0x1000 |
6 | 64 | 0x40 |
8 | 256 | 0x100 |
Exercise, Book 2.3:
Decimal | Binary | Hexadecimal |
0 | 00000000 | 0x00 |
158 | 10011110 | 0x9E |
76 | 01001100 | 0x4C |
145 | 10010001 | 0x91 |
174 | 10101110 | 0xAE |
60 | 00111100 | 0X3C |
361 | 11110001 | 0XF1 |
43981 | 1010101111001101 | 0xabcd |
123 | 01111011 | 0x7B |
117 | 01110101 | 0x75 |
189 | 10111101 | 0xBD |
245 | 11110101 | 0xF5 |
Exercise, Book 2.4:
Solve below subtraction and addition operations.
- 0x605c – 0x5 = _______________________
- 0x605c – 0x20 = ______________________
- 0x605c + 32 = _______________________
- 0x60fa – 0x601fc = __________________
Boolean/Logical Operations:
Operations (bit wise) are ~, &, | , and ^ encode logical operations for not, and, or, and exclusive-or, respectively
- AND operation: 0110 & 1100 = 0100
- OR Operation: 0110 | 1100 = 1110
- Exclusive-OR Operation: 0110 ^ 1100 = 1010
- NOT Operation: ~0110 = 1001
Bit Level Operations:
C Expression | Binary Expression | Binary Result | Hexadecimal Result |
~0x41 | ~ 01000001 | 10111110 | 0xBE |
~0x00 | ~ 00000000 | 11111111 | 0xFF |
0x69 & 0x55 | 01101001 & 01010101 | 01000001 | 0x41 |
0x69 | 0x55 | 01101001 | 01010101 | 01111101 | 0x7D |
Shifting operations: Book 2.1.9
Exercise, Book 2.16:
Operations | Value 1 | Value 2 |
Argument x | 01100011 | 10010101 |
x << 4 | 00110000 | 01010000 |
x >> 4 | 00000110 | 00001001 |
x >> 4 (Arithmetic) | 00000110 | 11111001 |
Do following exercise by yourself.
![](https://coursecs.wordpress.com/wp-content/uploads/2024/02/logical-operation.jpg?w=1024)
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.