Binary and Hexadecimal Basics

Contents
  1. Binary
  2. Hexadecimal
  3. Unsigned and Signed Binary Numbers
  4. Binary Shifts

1. Binary

CPUs are made up of billions of tiny switches. These switches can either be on or off and cannot work with the numbers we use (denary, 0-9) or our languages. Everything on a computer must be broken down to binary (0s and 1s). 0 = Off 1 = On Humans use denary numbers and It’s difficult for humans to understand binary numbers. We can convert between binary and denary numbers.

 At GCSE, you will only ever work with 8 bit numbers - binary numbers which contain 8 ones or zeros. For example:

0110 1110



2. Hexadecimal

What happens if you need to display a large binary number such as:

1111 1011 1111 1010 0011

Larger binary numbers are hard to remember and hard to write out without making a mistake. Hexadecimal is a number system (base-16) and makes use of 0-9 and A-F. It allows us to work with binary numbers in a more manageable way. Each 4 bits of a binary number can be represented with 1 hexadecimal digit. For example:

1011 = B

Hexadecimal numbers are used commonly when representing colours on web pages.


3. Unsigned and Signed Binary Numbers

Unless stated otherwise, most binary numbers you will work with are unsigned. Unsigned binary numbers all represent positive values. Signed numbers can represent positive and negative values. There are three methods of signing binary numbers: Sign Magnitude, One's Complement, and Two's Complement. Sign Magnitude In Sign Magnitude we use the most significant bit (the left most binary digit) to represent if the value is positive or negative. If the left most digit is a 1 it is negative, if it is a 0 then it is positive. An 8 bit Sign Magnitude number can represent values between 127 and -127.

 

Sign Magnitude is rarely used, if at all, due to a few issues. You cannot easily add two Sign Magnitude numbers together using standard binary addition and you can also end up with positive and negative 0 values:

1000 0000 = negative 0

0000 0000 = positive 0

One's Complement With One's Complement we start with a positive binary number and we flip all of the bits (1s become 0s and 0s become 1s).

 

Unlike Sign Magnitude, standard binary addition will work on One's Complement numbers. However, there are still positive and negative 0 values:

1111 1111 = negative 0

0000 0000 = positive 0

Two's Complement Two's Complement is the most commonly used method of representing negative numbers on a computer. The process of generating a negative Two's Complement number starts the same was as One's Complement: you take the positive version of your binary number and flip all of the bits (1s become 0s and 0s become 1s). After, you add 1 to the value of the number.

 

When working with Two's Complement the most significant bit (the left most bit) represents a negative number. In an 8 bit number the most significant bit would represent -128. Two's Complement works with standard binary addition, and does not have a negative and positive 0.


4. Binary Shifts

Binary Shifts allow us to multiply binary numbers by moving the position of the 1s.