2
LN 2: FIT1001 Computer Systems
5
Binary and Decimal
•
Binary number system (base 2)
– uses powers of 2 for each position in a number
•
Decimal number system (base 10)
– uses powers of 10 for each position in a number
•
Any integer quantity can be represented exactly using any
base (or radix)
– The
decimal
integer 947 in powers of 10:
>9
×
10
2
+ 4
×
10
1
+ 7
×
10
0
– The
binary
number 11001 in powers of 2 is:
>1
×
2
4
+ 1
×
2
3
+ 0
×
2
2
+ 0
×
2
1
+ 1
×
2
0
>
16
+
8
+ 0
+
0
+
1
=
25
•
When the radix is something other than 10, the base is
denoted by a subscript
– 11001
2 = 2510
(Sometimes, the subscript 10 is added for emphasis)
LN 2: FIT1001 Computer Systems
6
Octal and Hexadecimal
•
Octal (base 8)
– uses 8 symbols 0, 1, 2, 3, 4, 5, 6 and 7 to denote values from 0
to 7
•
Hexadecimal (base 16)
– uses 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F to
denote values from 0 to 15
– represents a shorthand version of binary numbers
– Example: 15528
10
= 3CA8
16
•
Base-2 and base-16 number systems enable you to
understand the operation of computer components
and the design of instruction set architectures
LN 2: FIT1001 Computer Systems
7
Binary, Hexadecimal and Octal
•
It is easy to convert between
– base 2 and base 16
– base 2 and base 8
•
To convert from binary to hexadecimal
– Group the binary digits into groups of four
> From right to left for integer part / left to right for fraction part
> Important to pad out with 0’s (to avoid errors)
– Example: convert the binary number 11010100011011
2
(= 13595
10)
to hexadecimal
•
To convert from binary to octal
– Group the binary digits into groups of three
> From right to left for integer part / left to right for fraction part
> Important to pad out with 0’s (to avoid errors)
– Example: convert the binary number 11010100011011
2 to octal
LN 2: FIT1001 Computer Systems
8
Binary Number System: Integers
•
Uses 2 symbols:
– 0 and 1
– Highest digit is 2-1
•
Example: the binary number 11001 in powers of 2 is:
–1
×
2
4
+ 1
×
2
3
+ 0
×
2
2
+ 0
×
2
1
+ 1
×
2
0
= 25
– The powers of 2 increase from right to left
•
A simple algorithm for calculating the successive binary
digits of a decimal integer X:
– Start from the right hand end:
>
Repeat
– Get the remainder from dividing X by 2
– Divide X by 2 and put the result in X
>
until
X is zero (the quotient = 0)
– The remainders in reverse order are the binary value
•
Example: Calculate the binary digits for X = 43
10