Information Technology Topic
Binary and Decimal Conversion
- Read notes
- Flashcards
- Quiz
- Confident
Study focus - 3 things
- Binary is base 2: only the digits 0 and 1, and each column is worth double the column to its right (… 128, 64, 32, 16, 8, 4, 2, 1)
- Binary to decimal: write the place values over the bits and add up the values that sit above a 1
- Decimal to binary: divide by 2 again and again, keep each remainder, and read the remainders from the last one up to the first
Section 1Why computers use binary
A computer works with electrical signals, and a signal can be in one of two states: a pulse is present or it is absent, a device is on or it is off. Binary has just two symbols, so it matches this exactly. One state is written 1 and the other is written 0. Switches, relays and transistors can all show these two states, and a row of them, such as 10001110, is a binary code. A single 0 or 1 is a bit (binary digit). Eight bits make a byte. Every number you type, in a spreadsheet at a Montego Bay call centre or on a calculator in class, is stored as a pattern of bits.
Section 2Place values in binary
In decimal (base 10) each column is worth ten times the one to its right: ones, tens, hundreds. In binary (base 2) each column is worth double the one to its right. Here's the trick: the place values for 8 bits are 128, 64, 32, 16, 8, 4, 2, 1. You can build them by starting at 1 and doubling. Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 A bit can only be 0 (that column is not counted) or 1 (that column is counted). That is the whole system.
Section 3Binary to decimal: add the place values
Write the place values above the bits. Add the place values that sit above a 1 and ignore the ones above a 0. Example, 1011 (a 4-bit number): Place value | 8 | 4 | 2 | 1 Bits | 1 | 0 | 1 | 1 So 1011 = 8 + 2 + 1 = 11. A longer one, 10110110: 128 + 32 + 16 + 4 + 2 = 182. Quick check: if the last bit is 1 the number is odd, because 1 is the only odd place value.
Section 4Decimal to binary: repeated division by 2
Divide the number by 2. Write the whole-number answer and the remainder (always 0 or 1). Divide the answer by 2 again. Keep going until the answer is 0. Example, 13: 13 ÷ 2 = 6 remainder 1 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 Read the remainders from the bottom up: 1101. So 13 = 1101 in binary. Watch out: the first remainder you get is the rightmost bit. Reading the list from the top gives the number backwards.
Section 5Decimal to binary: the place-value method
You can also use the place values directly. Start at the largest place value that fits and work right. Example, 45 in 8 bits: 128 is too big (0), 64 is too big (0), 32 fits (1) leaving 13, 16 is too big (0), 8 fits (1) leaving 5, 4 fits (1) leaving 1, 2 is too big (0), 1 fits (1) leaving 0. Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 Bits | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 So 45 = 00101101. Both methods give the same answer, so use one to check the other.
Section 6How big can an n-bit number be?
Each extra bit doubles the number of patterns. One byte (8 bits) can show 2^8 = 256 different values. Counting from 0, that is 0 to 255. The largest n-bit whole number is all 1s, which equals 2^n − 1. For 4 bits that is 1111 = 15, and for 8 bits that is 11111111 = 255. Zeros at the left do not change the value: 00000111 and 111 are both 7. Computers keep them so every number fills the same number of bits, which is why we often write 8-bit answers as 00101101 instead of 101101.
Section 7Checking your answer
Always convert back. If you changed 197 to binary, add the place values of your answer and make sure you get 197 again. Check the length too. A number between 128 and 255 needs 8 bits and must start with 1. A number below 16 fits in 4 bits. This topic uses whole numbers only, and values small enough for 8 bits. Octal and hexadecimal are in the next topic.
Examples
A technician in Kingston reads the 5-bit code 10110 from a machine display. (a) Write the place value above each bit. (b) Convert 10110 to decimal. (c) Check your answer by converting the decimal number back to binary with repeated division.
(a) A 5-bit number has place values 16, 8, 4, 2, 1. Place value | 16 | 8 | 4 | 2 | 1 Bits | 1 | 0 | 1 | 1 | 0 (b) Add the place values above the 1s: 16 + 4 + 2 = 22. The 8 and the 1 sit above 0s so they are not counted. So 10110 = 22. (c) 22 ÷ 2 = 11 remainder 0 11 ÷ 2 = 5 remainder 1 5 ÷ 2 = 2 remainder 1 2 ÷ 2 = 1 remainder 0 1 ÷ 2 = 0 remainder 1 Read the remainders from the bottom up: 10110. This matches the original code, so the answer is correct.
A shop in Mandeville stores each item code as an 8-bit binary number. One item has the code 197. (a) Convert 197 to 8-bit binary using repeated division by 2. (b) Check the result by adding place values. (c) State how many different item codes the shop could have with 8 bits, and the largest decimal code.
(a) 197 ÷ 2 = 98 remainder 1 98 ÷ 2 = 49 remainder 0 49 ÷ 2 = 24 remainder 1 24 ÷ 2 = 12 remainder 0 12 ÷ 2 = 6 remainder 0 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 Reading from the bottom up: 11000101. That already has 8 bits. (b) Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 Bits | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 128 + 64 + 4 + 1 = 197. The answer is confirmed. (c) 8 bits give 2^8 = 256 different codes, counted from 0. The largest is 11111111 = 255, which is 2^8 − 1.
Now let's water it
Session runs notes to flashcards to quiz back-to-back.
Where this comes from
- CSEC Information Technology Syllabus (CXC 30/G/SYLL 08, revised 2000, 2008, 2013) · Caribbean Examinations Council (CXC) · Section 1, Specific Objective 9 · Syllabus scope
- NEETS Module 13, Introduction to Number Systems and Logic Circuits (NAVEDTRA 14185, September 1998) · US Navy (Naval Education and Training Professional Development and Technology Center) · Chapter 1, The binary number system (base and symbols, positional notation, Table 1-2, and devices that show 1 and 0 as on and off), pages 1-9 to 1-12, checked against (https://vtda.org/bits/other/US_Navy/NEETS/US%20Navy%20NEETS%20-%20Module%2013-Introduction%20to%20Number%20Systems%20and%20Logic%20NAVEDTRA%2014185.pdf) · Facts
- NEETS Module 13, Introduction to Number Systems and Logic Circuits (NAVEDTRA 14185, September 1998) · US Navy (Naval Education and Training Professional Development and Technology Center) · Chapter 1, Conversion of bases, Decimal to binary (repeated division by the radix) pages 1-38 to 1-41, and Binary to decimal (positional notation) page 1-54, checked against (https://vtda.org/bits/other/US_Navy/NEETS/US%20Navy%20NEETS%20-%20Module%2013-Introduction%20to%20Number%20Systems%20and%20Logic%20NAVEDTRA%2014185.pdf) · Facts
- Navy Electricity and Electronics Training Series (NEETS), Module 22, Introduction to Digital Computers (NAVEDTRA 14194, September 1998) · US Navy (Naval Education and Training Professional Development and Technology Center) · Chapter 4, Bits and bytes, page 4-8, checked against (https://vtda.org/bits/other/US_Navy/NEETS/US%20Navy%20NEETS%20-%20Module%2022-Introduction%20to%20Digital%20Computers%20NAVEDTRA%2014194.pdf) · Facts