0% found this document useful (0 votes)
13 views72 pages

Binary and Hexadecimal Number Systems

This document presents the binary and hexadecimal numbering systems. It explains the representation of numbers in these bases, as well as the methods for converting between binary, decimal, and hexadecimal bases.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views72 pages

Binary and Hexadecimal Number Systems

This document presents the binary and hexadecimal numbering systems. It explains the representation of numbers in these bases, as well as the methods for converting between binary, decimal, and hexadecimal bases.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Part 1:

Binary and Hexadecimal Calculation

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

b) =12 where I = 1 and = 5

3
Number system
parADDITION
● Roman numerals: a system of
numbering by complex addition:

Example: MCMLXXXIX = 1989

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

The special role of Zero (0)!

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

● Remnants of other systems here and there in our culture,


which ones?

● Other bases are sometimes used...

9
Other Bases
In a base B, we construct the numbers with the
B digits {0, 1, 2,…, B-1}

● Example: base 2, with the symbols {0, 1}


Notation (example): 1001012
Binary system

● Example: base 8, with the symbols {0, 1, 2, 3, 4, 5, 6, 7}


Notation (example): 10050178
Octal system

● Example: base 16, symbols 0....9, A,B,C,D,E,F


Notation (example): 4AF216
Hexadecimal system
10
Binary System
base 2

B = 2 with digits the symbols {0, 1}

A digit = a Bit (binary digit) can be either 0 or 1

Vocabulary:

Octet (= byte, in general) = 8 bits (example ASCII code)


Note 1MB = 1 megabyte and 1Mb = 1 megabit
1MB = 1 megabyte

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

14235= 1 * 53+ 4 * 52+ 2 * 51+ 3 * 50


= 1* 125 + 4* 25 + 2*5 +3*1
= 23810

12
Base B Conversion → Decimal
Base B :(dn-1dn-2...d2d1d0)B= ? 10

(dn-1dn-2...2d1d0 (d =B n-1)*Bn-1+dn-2*Bn-2+...+d2*B2+ d 1*B1+d0*B0) 10

Example: in base 10:

147310= 1 * 103+ 4 * 102+ 7 * 101+ 3 * 100


1*1000 + 4*100 + 7*10 +3*1 = 147310
Example: in base 3:

2123= 2 *32+ 1 *31+ 2 * 30


= 2* 9 +1* 3 + 2*1
= 2310

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

● Example 2: 330 divided by 5

18
Decimal to 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)

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 .

Div parB =>d


2 n-3 n-4
Div parB => DivB => dn-1*B +dn-2*B +...+d2
...
n-1
Div parB => DivB =>dn-1

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

2) Decimal to BaseB conversion


Euclidean division by cascaded

27
Conversion: baseB → baseC

Method?

28
Conversion: baseB→ baseC
Method: (in 2 stages)
1) Base B conversion → Decimal

(dn-1dn-2d2d1d0 )B = (dn-1*Bn-1+dn-2*Bn-2+...+d2*B2+ d 1*B1+d0*B0)10

2) Decimal to BaseC conversion


Cascaded Euclidean Division

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

2- Decimal to Binary Conversion: 2 Methods

M1: successive divisions by 2

M2: subtraction of powers of 2

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

Practical example of converting decimal to binary:


Conversion de2410in binary = 110002

35
2 - Decimal to Binary Conversion
Method 2: Subtraction/Summing of Powers of 2

● Subtraction/Sum of Powers of 2

EXAMPLE: 5310= ?2

53 10= 32 + 16 + 4 + 1 = 25+24+22+20= 110101 2

Question: How many bits are needed to write 53? 10


36
Exercises: Binary to Decimal Conversion

Convert to decimal (base 10):

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

Convert to binary (base 2):

1010= ?2
11710= ?2
25510= ?2
74210= ?2

39
SOLUTIONS: Decimal to Binary Conversion

Convert to binary (base 2):

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

● All numbers with n digits are located in


the interval: [Min(n)BMax(n)B]

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

Min(2)10= 10 2 chiffres = [10 , 99]

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

Min(2)10= 10 2 digits = [10, 99] = [101, 102-1

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

Min(2)2= 102= 210 2 chiffres = [2 , 3]

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

Min(2)2= 102= 210 2 digits = [2, 3]

Max(2)2=112= 310
Min(3)2= 1002= 410
3 chiffres = [4 , 7]
Max(3)2=111=
2 710

Min(n)2= (2n-1)10 n bits = [2n-1 , 2n-1]


Max(n)2= (2n-1)10 n≥2
47
In binary if ...
Min(n)2=(2n-1)10
Max(n)2=(2n-1)10

What is 1111 worth?2in decimal (?)10)


Réponse : 11112is the largest 4-bit number
Max(4)2
(24-1)10(15)10

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

Method: to calculate the number of bits needed to represent X10:


find in the series of 2nthe greatestnwho is less than or equal to X10

example: how many bits are needed to represent 4710in binary?


Look for the biggest onenwho is less than or equal to 4710
25= 32 < 4710<26= 64
Réponse: 6 bits
52
exercises
● How many bits are needed to write in binary:
– 1210
– 7310
– 12710
– 31210
– 25710
– 102410

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

Comparison between binary, decimal, and hexadecimal systems


57
Hexadecimal to Decimal Conversion
● Example

● 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

● Example: conversion of 91810in base 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

7410= 100 10102= 4A16

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

You might also like