Equivalent to ((((((1 * 2) + 1) * 2) + 0) * 2) + 1)
Adding binary numbers: 01001011 + 10001101 = 11011000
How many bits does it take to store this number?
Hexadecimal numbers - base 16
Hexadecimal numbers use 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, F)
Natural for computers since 4 bits = one hex digit
Example:
4A7h = (4 * 16^2) + (10 * 16^1) + (7 * 16^0) = 1024 + 160 + 7 = 1191
Equivalent to ((((4 * 16) + 10) * 16) + 7)
Adding hex numbers: 4A7 + BE0 = 1087h = 4231d
How many bits does it take to store this number?
Octal numbers - base 8
Octal numbers use 8 digits (0, 1, 2, 3, 4, 5, 6, 7, 8)
3 bits = one octal digit
Example:
235o = (2 * 8^2) + (3 * 8^1) + (5 * 8^0) = 128 + 24 + 5 = 157
How many bits does it take to store this number?
Data Storage
Computer memory is all bits.
In our systems, each word is 32 bits long
That means that in one word we can store any number between 0 and 2^32
- 1 = 4294967295
Bit operations: shifting, masking
-
In Borland C++,
A char is 1 byte = 8 bits
A short is 2 bytes = 16 bits
An int is 4 bytes = 32 bits
A long is 4 bytes = 32 bits