Unleash Your Potential - Namagunga Girls Coding Club
Binary reference guide csit vn1202
1. Bits & Bytes – foundations of a digital age
A Handy Reference Guide To
The Binary System
For IT Students
Created 11 Jul 2012, John Walker Page 1 of 12
2. A Guide to the Binary System
The Digital Age
The “Digital Age” has been with us for some decades now. But what do we mean when we say
that something is “digital” and how is information, software, music and video stored and
processed by these devices?
Many of us are familiar with using computers at home, school and work. As IT students here at
TAFE, you will be tackling some advanced concepts of network engineering and systems
administration. In order to understand just how computers, their operating systems and
applications work, you will find it useful to investigate the underlying binary system of zeros and
ones which form the basic building blocks of digital technology.
Data and programs in computers are all represented by sequences of zeros or ones and
computation is performed using binary arithmetic. The reason for this choice is quite simple,
with only two possible options, it is easy to represent the zeros or ones as switches being on/off,
magnetic fields being present or not, light beams being on/off, electrical current being on/off.
Page 2 of 12 Created 11 Jul 2012, John Walker
3. A Guide to the Binary System
Decimal System
Let’s start with a numbering system we are all familiar with – the Decimal System, which gets its
name from the Latin word Decem, meaning ten. The Decimal system uses 10 symbols to
represent the digits 0,1,2,3,4,5,6,7,8,9.
Think about what happens when we count from zero to 20 in this system. We start with a single
column of digits as we count from zero to 9 and then what happens? We introduce another
column to the left of this first one and put a 1 in this column as we continue to count
10,11,12,13,14,15,16,17,18,19. At this point we need to introduce the next available symbol in
the leftmost column to give us 20.
This continues with a changeover each time we reach 9, increasing the leftmost column to the
next available symbol, until we reach 99. We now have to bring in a third column to the left of
the first two, and once again start with the first available symbol to give us 100. So let’s just
think for a moment just what we mean when we write a number such as 153. The rightmost digit,
3, represent 3 units, but the middle digit, 5, actually represents 5x10 – 50, while the leftmost
digit, 1, represents 1x10x10 = 100. You can see that a symbol in the leftmost column actually
has a much higher value than that in the rightmost column. In this system we refer to the digit on
the far right as the Least Significant Digit (LSD) and that on the far left as the Most Significant
Digit (MSD).
At this point I would like to introduce another concept from maths, that of powers of a number.
Most of us are probably reasonably familiar with 10 squared or 10 to the power of 2, meaning 10
multiplied by itself, to give 100. Likewise we might say 10 cubed or 10 to the power of 3
meaning 10x10x10 = 1000.
There are two more important powers with which we might not be as familiar. Any number to
the power of 1 is equal to itself. So 10 to the power of 1 = 10 and 2 to the power of 1 is 2. A
slightly less intuitive power is zero – any number to the power of zero is equal to 1. So 10 to the
power of zero is 1, but so is 2 to the power of zero, or 16 to the power of zero, and so on.
Getting back to our columns of symbols in the decimal system we can now look at the values of
the symbols in each column being the symbol multiplied by a relevant power of 10, as in the
following table, representing the value of the decimal number 2345.
Powers of 10
103 102 101 100
Decimal Number 2345 2 3 4 5
Values represented 2x10x10x10=2000 3x10x10=300 4x10=40 5x1=5
So we can determine the value of the number represented by the decimal symbols 2345 as being
2 thousand, plus 3 hundred, plus forty, plus five.
Page 3 of 12 Created 11 Jul 2012, John Walker
4. A Guide to the Binary System
Binary System
Now let’s take a look at the binary system, which gets its name from the Latin Bini (two-by-
two). In this system we only have two symbols to work with, 0 and 1. So if we were to start
counting from zero, we would get to 1 and immediately have to resort to another column to the
left, giving us 10, followed by 11 and once again we run out of symbols and have to resort to a
third column on the left, giving us 100. Note that at this stage we have only counted to the
equivalent of 4 in Decimal, but already need 3 digits to represent it in the binary form of 100. If
we investigate this a little further we see that the same rule regarding powers applies, with 20 =1,
21 =2, 22=4 and 23=8.
Note that here we are working with just 4 binary digits (called bits for short). With just 4 bits we
can only represent numbers from 0 to 15 which will do for this study of binary, octal and
hexadecimal numbers.
The table below shows the binary numbers 0011 and 1111 which represent the decimal 3 and 15
respectively
Powers of 2 (Using 4 bits)
23 22 21 20
Decimal 3 Binary Number 0011 0 0 1 1
Value represented 0x2x2x2=0 0x2x2=0 1x2=2 1x1=1
Decimal Binary Number 1111 1 1 1 1
15
Value represented 1x2x2x2=8 1x2x2=4 1x2=2 1x1=1
The table below now shows how we would count all the way from 0 to 15 in binary.
Note that 0000 is the lowest and 1111 is the highest number that we can represent with 4 bits.
Decimal Binary
(Using 4 bits)
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
Page 4 of 12 Created 11 Jul 2012, John Walker
5. A Guide to the Binary System
Powers of 2 (Using 8 bits)
27 26 25 24 23 22 21 20
Decimal Binary 0 0 1 0 1 0 1 0
42 Number
00101010
Values - - 32 - 8 - 2 -
represented
Decimal Binary 0 1 1 1 1 1 1 1
127 Number
01111111
Values - 64 32 16 8 4 2 1
represented
Decimal Binary 1 1 1 1 1 1 1 1
255 Number
11111111
Values 128 64 32 16 8 4 2 1
represented
The table above shows how we can represent Decimal 42 as 32+8+2, 127 as
64+32+16+8+4+2+1 and 255 as 128+64+32+16+8+4+2+1
Being able to convert Decimal numbers into 8-bit binary will become useful to you when
working with the TCP/IP network protocol when you wish to apply a mask to an IP address in
order to distinguish the network portion from the host computer ID. This is essential in
determining if two computers are actually on the same logical network segment.
The binary numbers of particular interest in subnetting are those with a continuous run of ones
from the left hand side. When used for a mask, the position of the first zero denotes the end of
the network ID section and the beginning of the host ID. Thus, the important numbers are:
Subnet MASKS
Decimal Binary
192 11000000
224 11100000
240 11110000
248 11111000
252 11111100
254 11111110
255 11111111
An example might be an address of 192.168.1.101 and a mask of 255.255.255.0
The IP address converted to binary becomes 11000000.10101000.00000001.01100101
The masks converted to binary becomes 11111111.11111111.11111111.00000000
ANDING (only 1 AND 1 = 1) yields network ID 11000000.10101000.00000001.00000000
The mask is applied by a process of ANDING the two binary rows together, which would yield
a network ID of 192.168.1.0 and host ID of 101. If another Host had an IP address of
192.168.2.100, it would actually be on a different network, with an ID of 192.168.2.0.
Page 5 of 12 Created 11 Jul 2012, John Walker
6. A Guide to the Binary System
Typically computers work with groups of bits which might be 4,8,16, 32 or 64 bits long. These
would give 24=16, 28=256, 216=65,536, 232=4,294,967,296 and 264=18,446,744,073,709,551,616
combinations respectively.
We normally refer to a group of 8 bits as a byte, which is the standard unit of data storage for
computers. So, when we refer to a Kilobyte we mean 210 = 1024 bytes of data. Likewise, a
Megabyte is 220 = 1,048,576 bytes, a Gigabyte is 230 = 1,073,741,824 bytes (roughly a Billion)
and a Terabyte is 240 bytes, which is a thousand Gigabytes.
Remembering that we start our numbering from 0, so the highest number in each case would be:
4 bit binary 1111
Decimal 15
8 bit binary 11111111
Decimal 255
16 bit binary 1111111111111111
Decimal 65535
32 bit binary 11111111111111111111111111111111
Decimal 4294967295
64 bit binary 1111111111111111 11111111111111111111111111111111111111111111111
Decimal 18446744073709551615
As you work with various aspects of Information Technology you will begin to see how these
groups of combinations, plus some in between ones (e.g. 12-bit and 24-bit) might effect certain
settings and limits. For example when setting the number of colours to display on your monitor
(depending on the quality of your video adapter) you will typically get a choice between 256
colours, 16-bit “high quality”, or 24-bit and 32-bit “true colours”). What this means is that while
16 bit can give you 65,536 colours, 24-bit can actually give 16 million possible colours for each
pixel displayed on your screen, hence the “true colour” tag.
Likewise, original IBM PC processors (8086) only used 20 bits to address RAM memory, giving
them a maximum limit of 1 Megabyte. Later processors used, 24-bits, 32-bits and more recently
36-bits giving maximum addressable memory of 16 Megabyte, 4 Gigabyte and 16 Gigabyte
respectively.
Page 6 of 12 Created 11 Jul 2012, John Walker
7. A Guide to the Binary System
Octal System
Writing out numbers in binary digits can be quite tedious and it is difficult to memorise
sequences of zeros and ones. So programmers and hardware engineers came up with a couple of
schemes to make this a little easier. One of these is the Octal system and another is Hexadecimal
(or Hex) which we will cover later.
Octal (from Octo – eight) uses just three binary bits per symbol, meaning we can only use,
0,1,2,3,4,5,6 and 7 before we have to resort to another set of 3 bits to continue with
10,11,12,13,14,15,16,17. Note that 10 Octal is 8 Decimal (23+0+0+0) and 17 Octal is actually 15
Decimal (23 + 22 + 21 +20)
If we compare this with our earlier table of Decimal to 4-bit Binary conversions we can see how
this works.
Octal 3-bit Binary Decimal 4-Bit Binary
0 000 0 0000
1 001 1 0001
2 010 2 0010
3 011 3 0011
4 100 4 0100
5 101 5 0101
6 110 6 0110
7 111 7 0111
10 001000 8 1000
11 001001 9 1001
12 001000 10 1010
13 001011 11 1011
14 001100 12 1100
15 001101 13 1101
16 001110 14 1110
17 001111 15 1111
Note that if we wanted to represent 9 bits of data using Octal, we could actually write this as a
sequence of 3 octal digits, for instance, in the range of 000 to 777. What we mean here is that
777 Octal actually represents the binary sequence 111 111 111.
One area where you will find doing this conversion useful is with Linux or Unix file
permissions, where Read, Write and eXecute permissions for users, group and others. can be
altered using the chmod command to set such permissions as 664 which sets the permission
string as rw-rw-r--. Similarly a setting of 777 would make the permissions rwxrwxrwx which
means that everybody has full read, write and execute access to the file.
Page 7 of 12 Created 11 Jul 2012, John Walker
8. A Guide to the Binary System
Hexadecimal System
Another way to more easily represent 4-bit binary sequences is to write them as Hexadecimal
(Hex) codes. Hexadecimal (from Hexadecem – sixteen) gives us 16 symbols to use in our
numbering system. The system uses the decimal digits 0 to 9, followed by the Alphabetic
characters A, B, C, D, E and F, as shown in the following table
Octal 3-bit Binary Decimal Hexadecimal 4-Bit Binary
0 000 0 0 0000
1 001 1 1 0001
2 000 2 2 0010
3 011 3 3 0011
4 100 4 4 0100
5 101 5 5 0101
6 110 6 6 0110
7 111 7 7 0111
10 001000 8 8 1000
11 001001 9 9 1001
12 001000 10 A 1010
13 001011 11 B 1011
14 001100 12 C 1100
15 001101 13 D 1101
16 001110 14 E 1110
17 001111 15 F 1111
So how might we use Hexadecimal? Apart from representing, for instance, the 4-bit Code 1101
as the symbol D we can also represent an 8-bit string of binary as two Hex codes together, such
as:
20 0010 0000
A5 1010 0101
EF 1110 1111
Where might we encounter Hex codes? Well one example is setting colour code for Web pages
in HTML . The colour code is entered as a # symbol followed by 3 pairs of hexadecimal codes,
representing amounts of Red, Green and Blue in the colour.
For example, Red is FF000, Green 00FF00 white is #FFFFFF, black #000000 and Silver is
#C0C0C0.
These codes would be easier to enter and remember than the full 24-bits of binary code they
represent.
Page 8 of 12 Created 11 Jul 2012, John Walker
9. A Guide to the Binary System
Another use might be in setting SCSI Hard Drive ID numbers, with a row of 4 jumpers being set
to represent the IDs 0 -15.
Page 9 of 12 Created 11 Jul 2012, John Walker
10. A Guide to the Binary System
Storing Text in Binary Format
The text which computers display on screen and print out also need to be stored as binary data.
This is done by using a table of codes to map codes to particular characters, both printable and
non-printable (for example TAB charactes and spaces). The American Standard Code for
Information Interchange (ASCII) is one such code which uses the first 128 codes (7-bits) to map
the basic standard characters and the remaining 128 for special characters. Various other codes
usually adhere to this ASCII standard for the first 128 codes but might use different character
sets beyond this. Below is a table showing the standard ASCII codes. Note how the code for an
uppercase A (41 Hex) is different from a lowercase a (61 Hex). This explains why it is
sometimes important, for instance, to use the correct case when entering passwords. We say that
some applications are “case sensitive” when they distinguish between Upper and Lower case in
this way
ASCII Table
Decimal Octal Hex Character Decimal Octal Hex Character
0 0 00 NUL 64 100 40 @
1 1 01 SOH 65 101 41 A
2 2 02 STX 66 102 42 B
3 3 03 ETX 67 103 43 C
4 4 04 EOT 68 104 44 D
5 5 05 ENQ 69 105 45 E
6 6 06 ACK 70 106 46 F
7 7 07 BEL 71 107 47 G
8 10 08 BS 72 110 48 H
9 11 09 HT 73 111 49 I
10 12 0A LF 74 112 4A J
11 13 0B VT 75 113 4B K
12 14 0C FF 76 114 4C L
13 15 0D CR 77 115 4D M
14 16 0E SO 78 116 4E N
15 17 0F SI 79 117 4F O
16 20 10 DLE 80 120 50 P
17 21 11 DC1 81 121 51 Q
18 22 12 DC2 82 122 52 R
19 23 13 DC3 83 123 53 S
20 24 14 DC4 84 124 54 T
21 25 15 NAK 85 125 55 U
22 26 16 SYM 86 126 56 V
Page 10 of 12 Created 11 Jul 2012, John Walker
11. A Guide to the Binary System
23 27 17 ETB 87 127 57 W
24 30 18 CAN 88 130 58 X
25 31 19 EM 89 131 59 Y
26 32 1A SUB 90 132 5A Z
27 33 1B ESC 91 133 5B [
28 34 1C FS 92 134 5C
29 35 1D GS 93 135 5D ]
30 36 1E RS 94 136 5E ^
31 37 1F US 95 137 5F _
32 40 20 SP 96 140 60 `
33 41 21 ! 97 141 61 a
34 42 22 " 98 142 62 b
35 43 23 # 99 143 63 c
36 44 24 $ 100 144 64 d
37 45 25 % 101 145 65 e
38 46 26 & 102 146 66 f
39 47 27 ' 103 147 67 g
40 50 28 ( 104 150 68 h
41 51 29 ) 105 151 69 i
42 52 2A * 106 152 6A j
43 53 2B + 107 153 6B k
44 54 2C , 108 154 6C l
45 55 2D - 109 155 6D m
46 56 2E . 110 156 6E n
47 57 2F / 111 157 6F o
48 60 30 0 112 160 70 p
49 61 31 1 113 161 71 q
50 62 32 2 114 162 72 r
51 63 33 3 115 163 73 s
52 64 34 4 116 164 74 t
53 65 35 5 117 165 75 u
54 66 36 6 118 166 76 v
55 67 37 7 119 167 77 w
56 70 38 8 120 170 78 x
57 71 39 9 121 171 79 y
Page 11 of 12 Created 11 Jul 2012, John Walker
12. A Guide to the Binary System
58 72 3A : 122 172 7A z
59 73 3B ; 123 173 7B {
60 74 3C < 124 174 7C |
61 75 3D = 125 175 7D }
62 76 3E > 126 176 7E ~
63 77 3F ? 127 177 7F DEL
For further details on ASCII (American Standard Code for Information Interchange)
http://www.asciitable.com/
Page 12 of 12 Created 11 Jul 2012, John Walker