Binary Numbers

Cards (50)

  • As computers only understand 1s and 0s, all data must be converted into binary to be processed. Binary can be used to represent all numbers in our standard number system
  • In our standard number system we have 10 different digits. This is called denary, decimal or base-10
  • Binary only uses 2 different digits (1 and 0) - we call this base-2
  • Counting in binary is similar to counting in denary, but the place values from right to left increase by powers of 2, instead of powers of 10
  • Denary to binary
    0 = 0
  • Denary to binary
    1 = 1
  • Denary to binary
    2 = 10
  • Denary to binary
    3 = 11
  • Denary to binary
    4 = 100
  • Denary to binary
    5 = 101
  • Denary to binary
    6 = 110
  • Denary to binary
    7 = 111
  • Denary to binary
    8 = 1000
  • Denary to binary
    9 = 1001
  • Denary to binary
    10 = 1010
  • Denary to binary
    11 = 1011
  • Denary to binary
    12 = 1100
  • Denary to binary
    13 = 1101
  • Denary to binary
    14 = 1110
  • Denary to binary
    15 = 1111
  • Most binary numbers are given as 8-bit numbers, e.g. 01101011, which can represent the denary numbers 0-255
  • Thr bit with the largest value is called the most significant bit, and the but with the smallest value is called the least significant bit
  • Drawing a table with binary place values in the first row makes binary to denary conversion easier
  • Example
    Convert the 8-bit binary number 10100110 to a denary conversion easier
    • Draw up a table with binary place values in the top row. Start with 2 at the right, then move left, doubling each time
    • Write the binary number 10100110 into your table
    • Add up all the numbers with a 1 in their column:
    > 128 + 32 + 4 + 2 = 166
    So 10100110 is 166 in binary
  • Binary numbers are easier to convert using tables
  • Convert denary to binary by subtracting
  • When converting from denary to binary, it's easier to draw a table of binary place values, then subtract them from largest to smallest
  • Example
    Convert the denary number 166 into an 8-bit binary number
    • Draw an 8-bit table
    • Move along the table, only subtracting the number in each column from your running total if it gives a positive answer
    • Put a 0 in every column that gives a negative answer, and a 1 in the rest
    >So 166 converted to an 8-bit binary number is 10100110
  • Example
    Add the following 8-bit binary numbers together: 10001101 and 01001000
    • First, put the binary numbers into columns
    • Starting from the right, add the numbers into columns
    • When doing 1 + 1 = 10, carry the 1 into the next column
    > So 10001101 + 01001000 = 11010101
  • Example
    Add the following 8-bit numbers together: 00110011 + 01111001
    • Start at the right-hand side and add each column
    • Sometimes you'll get something like 1 + 1 + 1 = 11, so you need to write 1, then carry 1 to the next column
    > So 00110011 + 01111001 = 10101100
  • Overflow errors can occur when a number has too many bits
  • Sometimes, during binary arithmetic you will get a result that requires more bits than the CPU is expecting - this is called overflow
  • In binary the 8-bit calculation 1111 1111 + 0000 0001 gives the 9-bit answer 10000 0000. Computers will see the 1 as an overflow error and just output 0000 0000
  • Computers usually deal with overflow errors by storing the extra bits elsewhere
  • Overflow flags are used to show that an overflow error has happened
  • In an overflow error, the most significant bit will be the first to overflow
  • Example
    a)Add the 8-bit binary numbers 01000110 and 11100010, giving your answer as an 8-bit number
    • Add the binary numbers in the usual way
    • The final calculation is 1 + 1 = 10, so carry the 1
    • You are left with a 9-bit answer - this is an overflow error
    • Ignore the overflow to give your 8-answer = 00101000
    b) Identify any problems that could be caused by giving your answer as an 8-bit number
    > There is an overflow error which can lead to a loss of data and a loss of accuracy in your answer. It could also cause software to crash if it doesn't have a way of dealing with the extra bit
  • The original 8-bit Pac-Man arcade game had an infamous overflow error. At level 256, half of the screen was replaced with glitchy colourful code
  • Binary shifts can be used to multiply or divide by 2
  • A binary shift (also known as a logical shift) moves every bit in a binary number left or right a certain number of places