You are on page 1of 15

Number Systems

&
Numbers Representation

1
Place Value and Base
• A number such as 6245 is in decimal
form, with each digit having a place value
Example : The place value of the digit 6 in
6245 is 1000 = 103
• Expanded form : 6245=6×103+2× 102 +4× 10
+5×100
• In decimal form, place values are powers of 10 so
the decimal system is said to have a base of 10
Note : base 10 requires ten digits (i.e. 0–9) 2
The Binary Number System
• Simplest number system is base 2, or binary
uses the 2 digits (“bits”) 0 and 1
• Used exclusively in computers (ON/OFF
switches, magnetised/unmagnetised memory
elements)
• A typical binary number is 10112
• The subscript 2 denotes the base – the base
should be included if it is not 10
3
Converting Binary to Decimal
• Example: Convert 10112 to decimal
• Solution: 11
= (1×23) + (0×22) + (1×21) + (1×20)
=8+2+1
= (11)10
11011 = 27
• Exercise: Convert 110001 to decimal
1 1 0 0 0 1 actual digits
32 16 8 4 2 1 place values
4
Decimal to Binary
• Repeatedly divide by 2,
writing down the quotient and remainder at
each step, until the quotient is zero
• Now write down the remainders in reverse
order – this is the binary form of the integer
• Example : Convert 212 to binary
Answer: 212 = 110101002
• Exercise : Convert 183 to binary
– 10110111
5
Example
2 212
106 0
53 0
26 1
13 0
6 1
3 0
1 1
0 1
Thus 212 = 110101002
6
The Octal and Hexadecimal
Systems
• The methods for converting from binary
(base 2) to decimal, and vice-versa, extend to
bases other than 2
(11012)2 invalid
• The base 8 number system is known as octal
we’ll look at number conversions, then at why
octal is useful in computing
(847)8 invalid
• Octal is based on the digits 0–7; the place
values are powers of 8
7
Converting Octal to Decimal
• Example: 2538
= (2×82) + (5×81) + (3×80)
= 128 + 40 + 3
= 171

• Exercise: Convert 1728 to decimal


Answer: 1728 = 122
Exercise: 2648 = ?
8
Converting Decimal to Octal
• Example: Convert 103 to octal
Solution:
Convert 103 by repeated division by 8;
103 = 1478

• Exercise: Convert 59 to octal


Answer: 59 = 738

9
Why is Octal Important?
• Computers use binary numbers exclusively
• However, binary numbers often have many
digits – e.g. 900010 = 010 001 100 101 0002
• Decimal uses fewer digits than binary, but
conversions between the bases are awkward
• Octal has two advantages:
– a fairly large base (so not too many digits)
– easy to convert between octal and binary
(as we’ll see in the next slides)
• Thus: octal is a good shorthand for binary
10
Conversion from Binary to Octal
Example: Convert 011 001 011 1012
to octal
Answer: 31358
Method: Group the bits into sets of three
adding extra zeros on the left if required to
complete a set of three bits. Then convert
each set of 3 bits to a single octal digit.
Task: Perform conversion of first 10 decimal
digits into binary
11
The Hexadecimal System
• The base 16 number system has the
advantages of octal (i.e. a relatively large
base, and easy conversions with binary) and it
also efficiently represents a byte
• Base 16 system is called hexadecimal (‘hex’)
• Hex uses 16 digits – the familiar 0-9, and the
upper-case letters A-F for 10-15,
representation.
• It is now the preferred shorthand for binary
12
To Convert Between Hex &
Decimal
• Example: Write 3AB16 in decimal form
Solution: 3AB16
= (3×162) + (10×161) + (11×160)
= 768 + 160 + 11 = 939
7C2916 = ( ? )10
• Example: Convert 730 to hex
Solution: Convert 730 using repeated
division by 16
– the answer is 2DA16
13
• 16 | 730
45 ------- 10
2----------13

2D A

6575= (?) 16

19A5
209F
19AF

14
To Convert Between Binary & Hex
• The method is the same as for conversions
between binary & octal, except that bits are
grouped into sets of four (rather than three)
• Example: Convert 0101 1011 0011
to hexadecimal
Answer: 5B316
• Example: Convert 3E716 to binary (use same trick
and group bits into sets of four)
Answer: 11111001112
15

You might also like