Intro to Computer Science / Unit 2: Binary and Data Representation
2.1 Binary Numbers
Notes
Binary is base 2: it uses only the digits 0 and 1. Each place value is a power of 2, doubling from right to left: 1, 2, 4, 8, 16, 32, 64, 128.
- To convert binary to decimal, add the place values that have a 1.
- Example: 101101 = 32 + 8 + 4 + 1 = 45.
- To convert decimal to binary, subtract the largest power of 2 that fits, repeatedly.
- Example: 13 = 8 + 4 + 1, so 13 is 1101.
- With n bits you can make 2 to the power n different values. 8 bits give 256 values (0 to 255).
Practice
What is the binary number 1101 in decimal?
8 + 4 + 0 + 1 = 13.
What is the decimal number 22 in binary?
22 = 16 + 4 + 2, so the bits are 10110.
What is the largest decimal number that can be stored in 8 bits?
8 bits make 256 values, from 0 up to 255.
Ready for more? Take the Unit 2 test.