Binary and Hexadecimal Number Systems
Binary and Hexadecimal Number Systems
1
Number system
(represent quantities by some)
symbols)
Difference?
a) IIIIIIIIIIII
b)
c) XII
d) 12
2
Numeration system
parADDITION
Onadditionnela valeur des différents
symbols
a) IIIIIIIIIIII = 12 where I = 1
3
Number system
parADDITION
● Roman numerals: a system of
numbering by complex addition:
4
Number systems
parPOSITION
1306= ?
5
Number systems
parPOSITION
1306=
1 thousand+
3 hundred
dozens
6 units
6
Numeration systems
parPOSITION
130610=
1x103+
3 times 102+
0x101+
6x100
10 is the base
7
The number zero
● Last digit entered:
– Represents the null quantity (abstraction)
● 0= NOTHING
– Allows the deviation in the notation by
position
● 1 ≠ 10 ≠ 100
8
Positional decimal notation
ordinary writing
● How to interpret 137?
● Notation: 137 ≡ 13710
(d2d1d0)10where the "dIuse the
10 symbols, from 0 to 9 = Base 10
9
Other Bases
In a base B, we construct the numbers with the
B digits {0, 1, 2,…, B-1}
Vocabulary:
11
General notation
In the BaseB: di {0, 1, 2,…, B-1} (the diare the numbers)
(dn-1dn-2...2d1d0)B(dn-1*Bn-1+dn-2*Bn-2+...+d2*B2+d1*B1+d0*B0)10
Example: in base 5
12
Base B Conversion → Decimal
Base B :(dn-1dn-2...d2d1d0)B= ? 10
13
exercise
● 124=?10
● 133=?10
● 1235=?10
● 11012=?10
● 107=?10
14
exercise
1 0
● 124=(1.4 + 2.4 )10= 610
● 133=impossible if B=3 ; digits = {0, 1, 2}
2 1 0
● 1235=(1.5 + 2.5 + 3.5 )10= 3810
3 2 1 0
● 11012(1.2 + 1.2 + 0.2 + 1.2 )10= 1310
1 0
● 107= (1.7 + 0.7 )10= 710
15
Decimal conversion → Base B
Our tool will be the Euclidean division
16
The Euclidean division
If x, y are integers and that
x=q.y+r
The division of x by y is noted:
Example: 7 = 3 . 2 + 1 and
y = divisor
q = quotient
r= remainder, r {0, 1, 2,…,y-1}
17
Cascaded Euclidean divisions
● Example 1: 7 divided by 2
18
Decimal to Base B
How to write the number X in base 10 in base B?
n-1 n-2 2 1
X10 = dn-1*B+dn-2*B+...+d2*B+d1*B+d0=B+d 0
.
Div parB=>X/B=d
10
19
Decimal conversion → Base B
How to write the number X in base 10 in base B?
Let X10= (dn-1dn-2...2d1d0)Bwe are looking for (dn-1dn-2...2d1d0)
X10 = dn-1*B+d
n-1 *B+...+d
n-2
n-2 *B+d *B+d
2 1
2
0 =B+d
1
0 .
In a table:
20
Decimal conversion → BaseB
=>Cascaded Euclidean division
● Example 1: 710(111)2
● Example 2: 33010(2310)5
21
exercises
● 510= ? 3
● 1910= ? 3
● 11710= ? 5
22
solutions
● 510= 12 3
23
solutions
● 1910201 3
24
solutions
● 11710= 432 5
25
exercises
● 510 = ? 5
● 210= ? 2
● 710= ? 7
● B10= ? B
26
reminder
1) Base B conversion → Decimal
(dn-1dn-2...d2d1d0)B(dn-1*Bn-1+dn-2*Bn-2+...+d2*B2+ d 1*B1+d0*B0)10
27
Conversion: baseB → baseC
Method?
28
Conversion: baseB→ baseC
Method: (in 2 stages)
1) Base B conversion → Decimal
29
example
123=?5
● 123= 1 . 3 + 2 = 510
● 2) 510= 105
30
exercise
● 1123=?5
● 124=?2
● 143=?9
31
solutions
● 1123= 1410245
● 124= 610=1102
● 143=?9impossible
32
The binary system
1- Binary to Decimal
33
1-Binary to Decimal
Binary Conversion B=2 -> Decimal
10110011012=?10
=71710
34
2 - Conversion Décimal -> Binaire
Method 1: successive division by 2
35
2 - Decimal to Binary Conversion
Method 2: Subtraction/Summing of Powers of 2
● Subtraction/Sum of Powers of 2
EXAMPLE: 5310= ?2
101110102= ?10
10102= ?10
20102= ?10
110010012= ?10
000000112= ?10
111112= ?10
37
Binary to Decimal
Solutions
10111010218610
10102= 1010
20102impossible
2012= 20110
000000112= 310
111112= 3110
38
Exercises: Decimal to Binary Conversion
1010= ?2
11710= ?2
25510= ?2
74210= ?2
39
SOLUTIONS: Decimal to Binary Conversion
1010= 10102
11710= 11101012
25510=111111112
7421010111001102
40
Magnitudes and number of digits
● Min(n)Bthe smallest number with n digits in
baseB
● Max(n)Bthe largest number of n digits in
baseB
41
Magnitudes and number of digits
In base 10: => range of numbers to
Min(1)10= 1 digit = ?
Max(1)10=
Min(2)10= 2 digits = ?
Max(2)10=
Min(3)10= 3 digits = ?
Max(3)10=
Min(n)10= in numbers = ?
Max(n)10=
42
Magnitudes and number of digits
In base 10: => interval of numbers to
Max(2)10= 99
Min(3)10= 100
3 chiffres = [100 , 999]
Max(3)10 = 999
Min(n)10= ? in numbers = ?
Max(n)10= ?
43
Magnitudes and number of digits
In base 10: =>interval of numbers to
Max(2)10= 99
3 digits = [100, 999] = [102, 103-1
Min(3)10= 100
Max(3)10= 999 n numbers = [10n-1 , 10n-1
Min(n)10= 10n-1 n≥2
Max(n)10= 10n-1
44
Magnitudes and number of digits
In base base2: => interval of numbers at
Min(2)2= ? 2 digits = ?
Max(2)2= ?
3 digits = ?
Min(3)2= ?
Max(3)2= ?
in numbers = ?
Min(n)2= ?
Max(n)2= ?
45
Magnitudes and number of digits
In base base2: => interval of numbers to
Max(2)2=112= 310
3 digits = [4, 7]
Min(3)21002410
Max(3)2=111=
2 710
in numbers = ?
Min(n)2= ?
Max(n)2= ?
46
Magnitudes and number of digits
In base 2: =>interval of numbers to
Max(2)2=112= 310
Min(3)2= 1002= 410
3 chiffres = [4 , 7]
Max(3)2=111=
2 710
48
exercises
● 11112=?10
● 1111112=?10
● 111111112=?10
● 11111111112=?10
49
solutions
● 11112Max(4)2= (24-1)10= 1510
● 1111112Max(6)2= (26-1)10= 6310
● 111111112Max(8)2(28-1)10= 25510
● 11111111112Max(10)2= (210-1)10= 102310
50
In binary if ...
Min(n)2(2n-1)10=> Min(n+1)2= (2n)10Max(n)2-1
Max(n)2=n-1)10
=> 2nis the smallest number of n+1 bits
51
In binary if ...
Min(n)2=(2n-1)10
Max(n)2=n-1)10
=>2nis the smallest number of n+1 bits
all the numbers between [2n , 2n+1-1]
They are written with +1n bits
53
solutions
● How many bits are needed to write in binary:
– 8 ≤ 1210requires 4 bits in binary writing
– 64 is less than or equal to 7310 requires 7 bits in binary writing
– 64 is less than or equal to 12710requires 7 bits in binary writing
– 256 is less than or equal to 31210requires 9 bits in binary writing
– 256 ≤ 25710requires 9 bits in binary writing
– 1024 ≤ 102410requires 11 bits in binary writing
54
Decimal to Binary Conversion
● Convert to binary
● 25410=
● 10910=
● 110010=
● 22110=
● 3410=
● Note: For each calculation, indicate the number of bits.
necessary.
55
Decimal to Binary Conversion
● Convert to binary
● 2541011111110
● 10910= 110 1101
● 110010= 100 0100 1100
● 22110= 1101 1101
● 3410 = 10 0010
● Note: For each calculation, indicate the number of bits.
necessary.
56
Hexadecimal System
● FB316=F*162+B*16 + 3*160
15 * 256 + 11 * 16 + 3
= 3840 + 176 +3 = 4019
58
Decimal to Hexadecimal Conversion
Method 1: Successive divisions by 16
Résultat =39616
59
Decimal to Hexadecimal Conversion
Method 2: Search for the highest
powers of 16
Example
67510= 322+ A * 161+ 3 * 160= 2A316
60
Hexadecimal <-> Binary Conversion
These are "easy" conversions
● Binary → Hexadecimal: with 4 bits of a binary
corresponds to a hexadecimal number:
1010-0111-10012= A -7- 9 = A7916
● Hexadecimal → Binary: to each digit
hexadecimal corresponds to 4 bits of a binary
F 9 6 B16= 1111 1001 0110 10112
61
Exercises: Hexadecimal ↔ Decimal
● Convert
F0016=?10
A1C16=?10
1BB16=?10
1 AD16=?10
2710=?16
7410=?16
23810=?16
25510=?16
62
solutions
F0016=384010
BD16=18910
10B16=26710
1 AD16=42910
63
Solutions
27101 10112=1B16
23810=111011102EE16
2551011111111=
2 FF16
64
Exercises: Hexadecimal <-> Binary
● Convert
1A16= ?2
AA16= ?2
1A116= ?2
100001012=?16
101111101012=?16
10000112=?16
11110101112=?16
65
solutions
1A16=110102=0001 10102
AA16101010102
1A116=1101000012=0001 1010 00012
1000 01012=8516
101 1111 01012=5F516
100 00112=4316
11110101112=3D716
66
exercises
● When switching from one encoding
(= representation of values) on 'n' bits to one
coding on 'n+1' bits what is the effect on the
number of values that can be represented?
67
solution
The number of representable values doubles
when we add 1 bit
– N bits = 2n numbers in [0 ; 2)n-1]
– N+1 bits = 2n+1 =2 x 2nnumbers in [0 ; 2n+1-1]
68
Exercises
● Conversion to decimal
● 12016=
● FE16=
● A1C16=
● 1BB16=
● A616=
● BB16=
69
Exercises: solutions
● Conversion to decimal
● 12016288
● FE16= 254
● A1C16= 2588
● 1BB16= 443
● A616 = 166
● BB16187
70
Exercises
Convert to binary or decimal:
For conversions to binary, how many bits do we need?
29410= ?2(?bits)
11002= ?10
10910= ?2(?bits)
1100001102= ?10
110010= ?2(?bits)
22110= ?2(?bits)
3410= ?2(?bits)
71
Solutions
Convert to binary or decimal:
For conversions to binary, how many bits do we need?
294101001001102(9bits)
11002equals 1210
10910= 11011012(7bits)
1100001102 = 390 10
110010= 100010011002(11bits)
22110= 2212(8bits)
3410= 1000102(6bits)
72