0% found this document useful (0 votes)
58 views31 pages

2) Number Systems: Dr. E. Lang

Uploaded by

Seth Vineet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views31 pages

2) Number Systems: Dr. E. Lang

Uploaded by

Seth Vineet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

2) Number Systems

Last update: 2020 September 15 Dr. E. Lang


© E. Lang

1
Table of Contents
2.1 Number Systems
2.2 Binary Number System
2.3 Hexadecimal Number System
2.4 Number System Conversions
2.4.1 Binary to Decimal
2.4.2 Hex to Decimal
2.4.3 Decimal to Binary or Hex
2.4.4 Conversion between Binary and Hex
2.5 Using a Calculator
2.6 Bytes
2.7 Summary

2
2.1) Number Systems
The number system we commonly use is a positional number system
where the value of each digit depends on its position. In addition, it is a
decimal, or base-10, system, since each digit is a multiple of a power of
10. As a consequence, there are only 10 distinct digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Example:
120.56 = 1 x 102 + 2 x 101 + 0 x 100 + 5 x 10-1 + 6 x 10-2

3
2.1) Number Systems
Historically, the first positional number system was the Babylonian
sexagesimal or base-60 system. In this system there will be 59 different
symbols since there is no symbol for 0:

We have inherited features of this system: 60 seconds in a minute and 360


degrees in a circle.
4
2.1) Number Systems
It is not necessary to use a positional system, and in fact other systems exit. For example,
the Roman numeral system is an additive system, but a smaller unit in from of a larger one is
subtractive. The following are the Roman numberals:

M = 1000
C = 100
D = 50
X = 10
V=5
I=1
So, for example:

MMXVII = M+M+X+V+I+I = 1000 + 1000 + 10 + 7 + 1 + 1 = 2017

MCMLXV = M-C+M+L+X+V+I+I = 1000 – 100 + 1000 + 50 + 10 + 5 = 1965


5
2.1) Number Systems
There is nothing unique about a base-10 system. A positional
number system on any other base could be defined.
With respect to computers, there are two important number
systems:

1) Binary (Base-2)
2) Hexadecimal, or Hex (Base-16)

6
2.2) Binary Number System
Since a computer is effectively a set of on/off switches, it is
convenient to represent data using a base-2, binary positional number
system. In this case each position represents a power of 2 and there are
only two distinct digits:
0, 1

Note: there is no digit 2 in the binary system, just as there is no digit for
10 in the decimal system.
For computer work, each binary digit is called a bit, and a byte = 8
binary digits or 8 bits.

7
2.2) Binary Number System
Example:
1101 = 1 x 10100 + 1 x 1010 + 0 x 101 + 1 x 100

= 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

Technically, the first line is completely correct, but for clarity the second form
is usually used. We shall use the second form.
The first line is based on the fact that

102 = 210

that is 10 (base-2) = 2 (base-10).


8
2.2) Binary Number System
Note that for clarity we sometimes use subscripts to indicate which
base we are dealing with:

102 = 210

9
2.2) Binary Number System
To add binary numbers, we need an addition table just as we need
an addition table to work with decimal numbers:

0 0 1 1
+0 +1 +0 +1
0 1 1 10

10
2.2) Binary Number System
Examples: Adding Binary Numbers

11
2.3) Hexadecimal Number System
Another number system that is commonly used for computer work
is the hexadecimal (or hex) number system. This system is based on
powers of 16.
In this system we need 16 distinct digits. Since we only have 10
digits from the decimal number system, letters are used for the rest:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

12
2.3) Hexadecimal Number System
When working with hexadecimal number it will be convenient to use
a table of equivalent values between the decimal and hex digits:
Decimal Hex Decimal Hex
0 0 8 8
1 1 9 9
2 2 10 A
3 3 11 B
4 4 12 C
5 5 13 D
6 6 14 E
7 7 15 F

13
2.3) Hexadecimal Number System
In the hex number system each position is a power of 16.

Example:
3A01 = 3 x 103 + A x 102 + 0 x 101 + 1 x 100

= 3 x 163 + A x 162 + 0 x 161 + 1 x 160

Again, the first line is technically the correct form, since

1016 = 1610

that is, 10 (base-16) = 16 (base-10). But for clarity we will use the second form.
14
2.3) Hexadecimal Number System
Again to add hex number we need an addition table. In this case it
would be 16x16. So it would be best to just look at some examples.

Examples: Adding Hexadecimal Numbers

15
2.4) Number System Conversions
We can convert between number systems:

• Binary to Decimal
• Hex to Decimal
• Decimal to Binary
• Decimal to Hex
• Binary to Hex
• Hex to Binary

16
2.4.1) Binary to Decimal
To convert a binary number to a decimal number, we simply expand
using the base expressed in decimal:

Example:
110 = 1x22 + 1x21 + 0x20 = 4 + 2 + 0 = 6
So,
1102 = 610

17
2.4.2) Hex to Decimal
To convert a hex number to a decimal number, we simply expand
using the base expressed in decimal and the decimal equivalents for the
letter numbers from the table:

Example:

A2C = 10x162 + 2x161 + 12x160 = 2560 + 32 + 12 = 2604


So,
A2C16 = 260410

18
2.4.3) Decimal to Binary or Hex
There are two algorithms that can be used to convert from decimal
to binary or hex.

Method 1:
1) Divide the decimal number by 2 or 16 and record the multiples of 2
or 16 and the remainder in a table.
2) For hex, if the remainder is between 10 and 15, convert to
equivalent letter.
3) Go back to Step 1 and continue until the multiple is 0.

19
2.4.3) Decimal to Binary or Hex
Method 2:
1) Find the largest power of 2 or 16 that will go into the number.
2) Record the number of times this largest power goes into the number
and also the remainder.
3) Find largest power of 2 or 16 that will go into the remainder.
4) Go to step 2 and repeat under there are no more powers of 2 or 16.

20
2.4.3) Decimal to Binary or Hex
Examples:

21
2.4.4) Conversion between Binary and Hex
The computer works with binary numbers, but binary numbers can
get very long. Hex provides a convenient short-hand way to represent
binary numbers. In addition the conversion between binary and hex is
very simple.
You should note that hex is often used for computer work, but this is
merely a convenience for persons working with computers. The
computer works in binary.

22
2.4.4) Conversion between Binary and Hex
We will need a table for conversions between hex and binary
numbers. Note that it is essential to keep all the leading zeros in the
binary numbers.
Decimal Binary Hex Decimal Binary Hex
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
23
2.4) Conversion between Binary and Hex
Hex to Binary: Use the following algorithm:

1) Look up the binary equivalent for each hex digit number in the table.
2) Under the hex digit write the binary equivalent.

Binary to Hex: Use the following algorithm:

3) Group the binary number in sets of 4; pad the number with 0s on the left
if necessary to compete a set of 4.
4) Look up the hex digit corresponding to each binary group of four in the
table.
5) Under each binary group of four, write the hex digit.
24
2.4) Conversion between Binary and Hex
Examples:

25
2.5) Using a Calculator
Most scientific and engineering calculators today can do some limited
calculations using alternate bases. The common one are

Base-10
Base-2
Base-8 (Octal)
Base-16

You will usually have to enter a different mode on your calculator. You can
tell if your calculator can work in different number systems if you see some
keys with A, B, C, D, E, F which are used to enter hex numbers.

26
2.5) Using a Calculator
Some calculators will also have Base-5, for what reason I know not.
The Octal system is now obsolete, but was used when bytes were 6
binary digits. In this case the conversion was like the hex-binary
conversion but with sets of 3 bits. For example:

111 110
7 6

You are expected to be able to do the conversions in detail. You can use
your calculator to check you work, but on exams you are expected to
show all the details of the calculation or you will get zero (0).

27
2.6) Bytes
The smallest addressable unit of a computer is the byte:

1 byte = 8 bits

Since each 4 bits can be represented as one hex digit, it takes 2 hex digits to
represent a byte. For example (note the space is just for convenience of reading and
has no significance):

1111 0010 = F2

This is the reason we use hexadecimal numbers in computer work, because the 8 bit
byte can be represented the shorter 2 hex digits.
28
2.6) Bytes
Since a computer is fundamentally binary, it is usual to use powers
of 2 to represent sizes:

210 bytes = 1,024 bytes = 1 kB (kilobyte)


220 bytes = 1,048,576 bytes = 1 MB (megabyte)
230 bytes = 1,073,741,824 bytes = 1 GB (gigabyte)
240 bytes = 1,099,511,627,776 bytes = 1 TB (terabyte)

And the number of bits is obtained by multiplying by 8 (1 byte = 8 bits).


29
2.7) Summary
We use a positional number system where the position represents a
power of the base. There is nothing unique about the base and any
base can be chosen.
For computer work we use three number systems:

1) Decimal: the working base of humans


2) Binary: the working base of computers
3) Hexadecimal: a convenient compressed way to represent binary
numbers that are grouped by bytes of 8 bits

30
2.7) Summary
You are responsible for knowing the following:

• Understanding and being able to work in decimal, binary and


hexadecimal number systems.
• Be able to do addition in the three bases.
• Be able to convert positive integers between any number system.
• Be able to define bits, bytes and sizes.

If required, on exams you will be given, the table in Slide 23.

31

You might also like