Intro to Computer Science / Unit 2: Binary and Data Representation
2.2 Binary Arithmetic and Hexadecimal
Notes
Binary addition works like decimal addition but carries when a column reaches 2. Hexadecimal (hex) is base 16 and uses digits 0-9 and letters A-F, where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
- Binary rules: 0+0=0, 0+1=1, 1+1=10 (write 0, carry 1).
- Example: 0110 + 0011 = 1001 (6 + 3 = 9).
- One hex digit equals exactly 4 bits, so hex is a short way to write binary.
- Example: 1010 1111 in binary is AF in hex, because 1010 is A and 1111 is F.
- Hex to decimal: 2F = 2 x 16 + 15 = 47. Hex is often used for colors, such as #FF0000 for red.
Practice
What is 0101 + 0010 in binary?
5 + 2 = 7, which is 0111.
What is the hexadecimal number 1A in decimal?
1 x 16 + 10 = 26.
A web page color is written #FF00FF. Each pair of hex digits is one color channel. What does FF mean in decimal?
FF = 15 x 16 + 15 = 255, the largest value of one byte.
Ready for more? Take the Unit 2 test.