Binary

What is Binary?

  • Binary refers to a system of representing information using only two digits: 0 and 1.

Bits

  • A bit is the smallest unit of digital information, representing either an “off” (0) or an “on” (1) state.

computer-bit The status of a computer bit being on or off.

Bytes

  • Bits are grouped into larger structures to form bytes (8 bits), words, and long words
  • These groupings allow us to represent more complex information, like numbers, text, and instructions

bytesandbits Groups bits to store more complex information

What do the 0s and 1s represent?

  • In binary, each level is based on powers of 2
  • In the 8-bit binary number below, each of the 8 columns represents values of , e.g.
  • = 1
  • = 2
  • = 4
  • = 8
  • = 16
  • = 32
  • = 64
  • = 128

powers-of-two Binary powers of two

Encoding and representation

  • Various encoding schemes, like ASCII for text or JPEG for images, map these binary values to human-readable forms
  • For example, the binary value 01001000 represents the letter ‘H’ in ASCII
  • In the example below, an image is shaded black or white depending on the binary value for each pixel
  • Each row in the image requires 1 byte of storage

pixel-shading Pixel-shading in a bitmap image

Abstraction layers

  • Computers handle large volumes of basic numeric data
  • To create meaningful representations of data, layers of abstraction exist so that basic data can be interpreted upwards into other forms, e.g. images, sound, video
  • The same principle applies to programming languages that compile down into binary code
  • At the bottom, you have binary, and each layer above it allows for more meaningful information to be represented

abstractions-of-binary Abstractions of binary

Converting Between Binary & Denary

  • Within computer science, two common number systems are:
    • Denary numbers – This is also known as base-10. These are used by humans and consist of 10 digits ranging from 0 to 9
    • Binary numbers - Computer systems store data using 1s and 0s. This is known as binary or base-2. Computer systems store data in binary format because computers are made up of circuits and switches that are either on (1) or off (0)
  • Binary numbers can be converted into denary and vice-versa
  • For example the 8-bit binary number 01101001 can be converted into denary using the following method:

binary-to-decimal Binary to decimal conversion

Therefore the 8-bit binary number 01101001 is 105 as a denary value.

Converting Between Denary & Binary

  • To convert the denary number 101 to binary, we firstly write out binary number system
1286432168421
        
  • Then we start at the left and look for the highest number that is less than or equal to 101 and if so, place a 1 in that column. Otherwise, place a 0 in the column
  • 128 is bigger than 101 and therefore we place a 0 in that column
  • 64 is smaller than 101 so we place a 1 in that column. 101 - 64 = 37. This now means we have 37 left to find
  • 32 is smaller than 37 so we place a 1 in that column. 37 - 32 = 5. This now means we have 5 left to find
  • 16 is bigger than 5 and therefore we place a 0 in that column
  • 8 is bigger than 5 and therefore we place a 0 in that column
  • 4 is smaller than 5 so we place a 1 in that column. 5 - 1 = 1. This now means we have 1 left to find
  • 2 is bigger than 1 and therefore we place a 0 in that column
  • 1 is equal to the number we have left so we place a 1 in that column
  • 64 + 32 + 4 + 1 = 101. Therefore the denary number 101 in binary is 01100101
1286432168421
01100101