To access the interactive and most up-to-date version of this course, follow the link at the bottom
of this document.
Introduction
This Course
This course aims to be a crash course on binary and its uses. It is suitable for all levels of ability and does
not require any prior programming knowledge.
By the end of this course, you will gain an understanding if the binary number system, as well as a more
in-depth understanding of the decimal system you will be already so familiar with. You will also be
introduced to the hexadecimal number system to offer an additional example and reinforce the structure
found within number systems. You will learn how to create negative binary numbers, and use operations
on binary such as addition, subtraction, and multiplication. You will learn how binary values can have
fractional parts and see how computers store these values using floating-point representation. Finally, we
will look at some of the real applications of binary with the ASCII encoding system.
This course will cover:
The basics of the decimal, binary and hexadecimal system
Conversions between each of the numeral system
Signed binary numbers (ones' complement and two's complement)
Binary operations (addition, subtraction, multiplication, bitwise operations)
Binary fractions and floating point (single and double precision)
ASCII
Bits and Bytes
Binary is the language that computers can understand. Binary is not as complicated as it seems, it is
simply a number system. A string of 1s and 0s can represent a specific value, if you know how to read it,
just like the decimal system we use for counting.
Some Terminology
The 'bi' prefix in 'binary' means 'two'. The word 'bit' stands for binary digit, and it can be one of two
values: 1 or 0.
A 'byte' is 8 bits.
Understanding Binary 1
, A 'nibble' is 4 bits.
The 'kilo' prefix means 'one thousand' or 1000.
If a file size is a kilobyte (kB), it means it is roughly one thousand bytes. As each byte is 8 bits, this is
eight thousand bits.
The 'mega' prefix means 'one million' or 1,000,000.
If a file size is a megabyte (MB), it means it is roughly one million bytes. As each byte is 8 bits, this is
eight million bits.
The 'giga' prefix is even larger and means 'one billion' or 1,000,000,000.
If a file size is a gigabyte (GB), it means it is roughly one billion bytes. As each byte is 8 bits, this is
eight billion bits.
Numeral Systems
The Decimal System
To fully understand Binary, first we will need to recap a numerical system that we already know well: the
decimal system.
The decimal system, just like all numerical systems, is a system to represent a value. We can write a
value using this representation down and we will know exactly what we meant later. If two people agree to
use the decimal system, we can also easily communicate a value to that other person, and they will know
exactly what value we mean.
The decimal system has a base of 10, meaning it has 10 digits to utilise when trying to represent any
value: the digits 0 to 9.
For each digit in a decimal number (e.g. 425), the position of that digit determines the value it adds to the
overall number. We can visualise this using column headings.
With 425:
The 5 is in the 'ones' column, so this means this digit represents 5 x 1 (= 5)
The 2 is in the 'tens' column, so this means this digit represents 2 x 10 (= 20)
The 4 is in the 'hundreds' column, so this means the digit represents 4 x 100 (= 400)
Understanding Binary 2
, From this we can get the value that '425' actually represents 400 + 20 + 5.
But we are so familiar with the decimal system and use it so frequently that this seems obvious and
intuitive. We're so used to multiplying numbers by 10, 100 and even 1000 that we don't find this
challenging.
Why Ones, Tens and Hundreds?
Let's take a closer look at why we use 'ones', 'tens' and 'hundreds' etc. in the column headings.
The decimal system uses base 10, so each column can hold 10 different digits (0 to 9) before we spill
over into the next column (to create the number 10).
With a single digit, we can store 10 different values
With two digits, we can store 10 x 10 = 100 different values
With three digits, we can store 10 x 10 x 10 = 1000 different values
If we follow the pattern, each column heading is actually the base of the number system (in decimal
system this is 10) to the power of the column number (starting from 0).
For example, with the decimal number 4982:
the 4 is in the 103 column
the 9 is in the 102 column
the 8 is in the 101 column
the 2 is in the 100 column
4 × 103 + 9 × 102 + 8 × 101 + 2 × 100 = 4982
Understanding Binary 3
, Remember: Anything to the power of zero is always equal to 1.
The Binary System
Binary is the same as the decimal system we are so familiar with, except for the fact that it uses a base of
2.
This means that our column headings are 2 (rather than 10) to the power of the column number. Rather
than the headings 100 , 101 , 102 ... (from right to left), we instead have 20 , 21 , 22 ... because each column
only has two digits to work with, rather than ten.
We represent the value of 'eighteen' in binary using five digits: 10010. There is a 1 in the 'sixteens'
column, and another 1 in the 'twos' column. We multiply each of the digits by their column headings to
get: 1 x 16 + 1 x 2, which equals 18!
As we only have digits of 1 or 0 to work with, rather than multiplying the column heading by a digit up to 9,
the largest digit we have now is just 1. When checking each column, we either add the column heading
towards the overall value if there is a 1 present in that column, or we don't add anything if there is a 0.
It's quite common to pad/extend your binary value so that it uses eight binary digits (or 'a byte'). We can
add as many zeros as we want to the left of a binary value and its value would not change. For example,
the binary for 'eighteen' only has to use five digits (10010), so we can pad it to become eight digits by
adding three zeros on to the left to create: 00010010.
Understanding Binary 4