0% found this document useful (0 votes)
10 views46 pages

Chap1 NumeralSystems EN

The document discusses information representation in binary systems. It introduces numeral systems and defines them based on their base. The most common systems are binary, octal, decimal, and hexadecimal. Conversions between these systems involve grouping bits or digits according to the target base. Signed numbers are represented in binary using either sign-magnitude or two's complement methods. Two's complement provides correct arithmetic results.

Uploaded by

luko berry
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)
10 views46 pages

Chap1 NumeralSystems EN

The document discusses information representation in binary systems. It introduces numeral systems and defines them based on their base. The most common systems are binary, octal, decimal, and hexadecimal. Conversions between these systems involve grouping bits or digits according to the target base. Signed numbers are represented in binary using either sign-magnitude or two's complement methods. Two's complement provides correct arithmetic results.

Uploaded by

luko berry
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
You are on page 1/ 46

Chapter 1:

Information representation in
binary
Architecture of microprocessor and microcontroller systems
Dr. Samer Lahouar ([email protected])
Class Notes: https://shorturl.at/arAEI
2 Introduction
The decimal numbering system (i.e., digits 0 to 9) is
not adequate to process and store information on a
PC
It’s unpractical to store numbers using the digits 0 to
9 (10 states) directly on an electronic circuit
It’s difficult to design electronic circuits that can do
operations (arithmetic or others) with the digits 0 to 9

 Solution: use another numeral system that can be


easily implemented on electronic circuits
S. Lahouar
3 Numeral Systems: Definitions (1)
A numeral system is composed of a set of ordered
digits that are used to represent numbers
It allows performing arithmetic operations, such as,
Addition, Subtraction, Multiplication, etc. according
to defined rules
A numeral system is defined by its Base B (or Radix)
B is the number of digits in the numeral system that
are used to represent all the numbers
Note: The difference between Digit and Number: a
finite set of digits is used to represent infinite
numbers
S. Lahouar
4 Definitions (2)
A number N in the numeral system of base B is
written as:
(N)B = (an-1an-2an-3…a1a0)B
where:
ai: digits used to represent N in base B (0 ≤ ai ≤ B-1)
n: number of digits ai used to represent N
The decimal value of N (in Base 10) is obtained by
the following polynomial:
𝑛−1

𝑁10 = ෍ 𝑎𝑖 𝐵𝑖 = 𝑎𝑛−1 𝐵𝑛−1 + 𝑎𝑛−2 𝐵𝑛−2 + 𝑎𝑛−3 𝐵𝑛−3 + ⋯ + 𝑎1 𝐵1 + 𝑎0 𝐵0


𝑖=0
S. Lahouar
5 Standard Numeral Systems:
 B=10: Decimal, ai = 0, 1, 2, 3, …,9
Ex. N10=(9308)10 = 9x103+3x102+0x101+8x100
 B=2: Binary, ai=0,1 (called bits for binary digits)
Ex. N2=(1011101)2 = 1x26+0x25+1x24+1x23+1x22+0x21+ 1x20
= 64+0+16+8+4+0+1 = (93)10
 B=8: Octal, ai = 0, 1, 2, 3, …,7
Ex. N8=(247)8 = 2x82+4x81+7x80=2x64+4x8+7=(167)10
 B=16: Hexadecimal, ai = 0, 1, 2, 3, …,9,A, B, C, D, E, F
Ex. N16=(C3)16 = 12x161+3x160=12x16+3=(195)10
 Note: these systems are the most used ones, but any
base could be utilized (ex. B=3, B=4, B=5, etc.)
𝑛−1

Polynomial: 𝑁10 = ෍ 𝑎𝑖 𝐵𝑖 = 𝑎𝑛−1 𝐵𝑛−1 + 𝑎𝑛−2 𝐵𝑛−2 + 𝑎𝑛−3 𝐵𝑛−3 + ⋯ + 𝑎1 𝐵1 + 𝑎0 𝐵0


𝑖=0
S. Lahouar
6 Maximum value of an n-digit number
Bn numbers could be represented with n digits in base B. These
numbers are in the range 0 to Nmax= Bn – 1
Examples:
 For B=10 and n=4, we have 104=10000 numbers in the range 0
to Nmax=104-1=9999
 For B=2:
 n=4, we have 24=16 numbers between 0 and Nmax=24-1=15
 n=8, we have 28=256 numbers between 0 and Nmax=28-1=255
 n=16, we have 216=65536 numbers between 0 and Nmax=216-1=65535
 For B=8 and n=4, we have 84=4096 numbers between 0 and
Nmax=84-1=4095
 For B=16 and n=4, we have 164=65536 numbers between 0
and Nmax=164-1=65535
S. Lahouar
7 Conversion: base B → base 10 (decimal)
The polynomial is used:
n −1
N=
10 
i =0
ai B i = an −1 B n −1 + an − 2 B n − 2 + an −3 B n −3 +  + a0 B 0

Examples:
B=2: (100101)2 =1x25+0x24+0x23+1x22+0x21+1x20
= 32+4+1= (37)10
B=16: (A3D)16 = 10x162+3x161+13x160 = (2621)10
B=8: (1025)8 = 1x83+0x82+2x81+5x80 = (533)10
B=7: (1025)7 = 1x73+0x72+2x71+5x70 = (362)10

S. Lahouar
8 Conversion: Base 10 (decimal)→ Base B
Digits ai should be determined.
The polynomial is divided by B:
𝑁10 𝑎𝑛−1 𝐵𝑛−1 + 𝑎𝑛−2 𝐵𝑛−2 + 𝑎𝑛−3 𝐵𝑛−3 + ⋯ + 𝑎1 𝐵 + 𝑎0
=
𝐵 𝐵
a0 < B N10 B
Remainder a0 𝑄1 = 𝑎𝑛−1 𝐵𝑛−2 + 𝑎𝑛−2 𝐵𝑛−3 + 𝑎𝑛−3 𝐵𝑛−4 + ⋯ + 𝑎1
Q1 B
a1 𝑄2 = 𝑎𝑛−1 𝐵𝑛−3 + 𝑎𝑛−2 𝐵𝑛−4 + 𝑎𝑛−3 𝐵𝑛−5 + ⋯ + 𝑎2
Q2 B
a2 𝑄3 = 𝑎𝑛−1 𝐵𝑛−4 + 𝑎𝑛−2 𝐵𝑛−5 + 𝑎𝑛−3 𝐵𝑛−6 + ⋯ + 𝑎3

Qn B
S. Lahouar
an-1 0
9 Conversion: Base 10 (decimal)→ Base B
Example 1: (95)10 = (?)2

95 2
1 47 2
a0
1 23 2
 (95)10 = (1011111)2
1 11 2
1 5 2
1 2 2
0 1 2
1 0
a6
S. Lahouar
10 Conversion: Base 10 (decimal)→ Base B
Example 2: (95)10 = (?)8

95 8
7 11 8  (95)10 = (137)8
a0
3 1 8
1 0
a2
Example 3: (95)10 = (?)16
95 16
15 5 16  (95)10 = (5F)16
a0 5 0
S. Lahouar a
11 Conversion Table: decimal, binary, octal and hexadecimal
Decimal Binary Octal Hexadecimal

0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4 Octal Digits
5 0101 5 5
6 0110 6 6
7 0111 7 7 Hex Digits
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
S. Lahouar
15 1111 17 F
12 Conversion from 2 → 8 or 16
Based on the previous table:
1 octal digit is represented by 3 bits (8=23)
1 hexadecimal digit is represented by 4 bits (16=24)
Therefore, to convert:
binary to octal, bits are grouped by 3 (starting from a0)
binary to hexadecimal, bits are grouped by 4 (starting from
a0)
Then, the previous table is used to make the conversion.
Examples: (1011111)2 = (?)8 et (1011111)2 = (?)16
(001011111)2 = (137)8
(01011111)2 = (5F)16
S. Lahouar
13 Conversion from 8 or 16 → 2
Using previous table, octal or hexadecimal digits are
converted to their equivalent binary representations:
1 octal digit: 3 bits
1 hexadecimal digit: 4 bits
Examples: (137)8 = (?)2 and (5F)16 = (?)2
(1 3 7)8=(001 011 111)2

(5 F)16=(0101 1111)2

S. Lahouar
14 Conversion between 8  16
The Binary system is used as intermediary system:
Examples: (271)8 = (?)16 and (2FA)16= (?)8
(271)8 = (010 111 001)2 = (0 1011 1001)2=(B9)16

(2FA)16=(0010 1111 1010)2=(001 011 111 010)2 =(1372)8

S. Lahouar
15 Signed numbers in binary
Signed number: Number which can be > 0 or < 0
In binary, the sign “-” does not exit, only “0” and “1”
bits are used.
A sign bit is added to the left of the number to
indicate its sign:
Sign bit = 0  N is Positive (>0)
Sign bit = 1  N is Negative (<0)

N= Sign bit Rest of the bits

Fixed number of bits


S. Lahouar
16 Signed Binary Numbers: Sign-Absolute value
Representation

N= SB Absolute Value of N

Examples: for n=5 bits:


(9)10 = (0 1001)2  (-9)10 = (1 1001)2
(15)10 = (0 1111)2  (-15)10 = (1 1111)2

Advantages:
Easy representation of signed numbers
Easy conversion between a number and its opposite

S. Lahouar
17 Signed Binary Numbers: Sign-Absolute value
Representation

N= SB Absolute Value of N

Drawbacks:
Double representation of 0:
For 5 bits: (0 0000)2 = 0 and (1 0000)2 = 0
Wrong results of arithmetic Operations:
For 5 bits: 14+(-14) = (?)2

1 1 1
14 = 0 1110
+ -14 = 1 1110
0 ≠10 1100
S. Lahouar
18 Signed Binary Numbers: 2’s complement
Representation
A negative number can be represented in binary
using 2’s complement defined as:
C2(N) = 2n – N
where n: number of bits of N.
Therefore, C2(N)+ N = 2n=0 (if only n bits are used for
number representations)  C2(N) =– N
2’s complement is found as follows:
Invert all the bits of N (1’s complement)
Add 1 to the least significant bit (the bit to the right)

S. Lahouar
19 Signed Binary Numbers: 2’s complement
Representation
Examples: for n=5 bits
 (9)10 = (0 1001)2
 (-9)10=C2(9)=C1(9)+1=1 0110+1= (1 0111)2
 (15)10 = (0 1111)2
 (-15)10=C2(15)=C1(15)+1=1 0000+1= (1 0001)2
 (0)10 = (0 0000)2
 (-0)10=C2(0)=C1(0)+1=1 1111+1= (0 0000)2 with 5 bits
 A unique representation of 0
 (14)10 = (0 1110)2
 (-14)10=C2(14)=C1(14)+1=1 0001+1= (1 0010)2
1 1 1
14 = 0 1110
+ -14 = 1 0010
S. Lahouar 0 =10 0000 0 with 5 bits
20 Signed binary numbers in 2’s complement: conversion
to decimal (Base 10)
Binary → Decimal conversion of a signed number in C2:
 n-bits signed number is represented by:
N2 = (an-1an-2an-3…a0)2 where an-1: sign bit
 Decimal value of N is obtained using the polynomial:
𝑁10 = −𝑎𝑛−1 2𝑛−1 + 𝑎𝑛−2 2𝑛−2 + 𝑎𝑛−3 2𝑛−3 + ⋯ + 𝑎0 20
Examples: For n=5 bits
 (1 0001)2=-1x24+0x23+0x22+0x21+1=-16+1=-15
 (1 0010)2=-1x24+0x23+0x22+1x21+0=-16+2=-14
 (1 0111)2 =-1x24+0x23+1x22+1x21+1=-16+4+2+1=-9
 (0 1111)2 =-0x24+1x23+1x22+1x21+1=8+4+2+1=15

S. Lahouar
21 Min and Max values of an n-bit signed number

With n bits, 2n signed numbers could be represented.


Their range is from Nmin = – 2n-1 to Nmax= 2n-1 – 1
Examples:
n=4, we have 24=16 numbers between:
Nmin = – 23= – 8 and Nmax=23-1=7
n=8, we have 28=256 numbers between:
Nmin = – 27=– 128 and Nmax=27-1=127
n=16, we have 216=65536 numbers between:
Nmin = – 215=– 32768 and Nmax=215-1=32767

S. Lahouar
22 Real numbers representation in binary (1)
A real number R is represented in binary as:
(R)2 = (an-1an-2an-3…a0,a-1a-2a-3…a-m)2

Integer Part Decimal (or fractional)


where: Part

 n: number of bits of the integer part


 m: number of bits of the decimal (or fractional) part
 ai: are the bits (ai = 0 or 1)
The base 10 (decimal) value of R is obtained using the polynomial:
𝑛−1

𝑅 = ෍ 𝑎𝑖 2𝑖 = 𝑎𝑛−1 2𝑛−1 + 𝑎𝑛−2 2𝑛−2 + 𝑎𝑛−3 2𝑛−3 + ⋯ + 𝑎0 20 + 𝑎−1 2−1 + 𝑎−2 2−2 + ⋯ + 𝑎−𝑚 2−𝑚
𝑖=−𝑚

S. Lahouar
Integer Part Decimal Part
23 Real numbers representation in binary (2)
(R)2 = (an-1an-2an-3…a0,a-1a-2a-3…a-m)2
𝑛−1

𝑅 = ෍ 𝑎𝑖 2𝑖 = 𝑎𝑛−1 2𝑛−1 + 𝑎𝑛−2 2𝑛−2 + 𝑎𝑛−3 2𝑛−3 + ⋯ + 𝑎0 20 + 𝑎−1 2−1 + 𝑎−2 2−2 + ⋯ + 𝑎−𝑚 2−𝑚
𝑖=−𝑚

Example:
 (1101.1101)2=1x23+1x22+0x21+1x20+1x2-1+1x2-2+0x2-3+1x2-4
= 8+4+0+1+1/2+1/4+0/8+1/16
= 13+0.5+0.25+0.0625
= 13.812510

S. Lahouar
24 Real numbers representation in binary (3)
To find the digits ai of the fractional part, it should be multiplied
successively by 2:
R = a-1 2-1+a-2 2-2+a-3 2-3+ … +a-m 2-m
 2R = a-1 +a-2 2-1+a-3 2-2+ … +a-m 2-m+1
Integer Decimal Part = R1

 2R1 = a-2 +a-3 2-1+ … +a-m 2-m+2


Integer Decimal Part = R2

 2R2 = a-3 +a-4 2-1+ … +a-m 2-m+3


Integer Decimal Part = R3


S. Lahouar
25 Real numbers representation in binary (4)
Examples:
 (27.625)10 = (?)2
 Integer part: 2710=110112 (Successive divisions by 2)
 Decimal part: 0.62510=0.1012 (Successive multiplications by 2)
 Therefore: 27.62510=11011.1012

(0.23)10 = (?)2
 0.23 × 2 = 0.46  a-1 = 0 et R1 = 0.46
 0.46 × 2 = 0.92  a-2 = 0 et R2 = 0.92
 0.92 × 2 = 1.84  a-3 = 1 et R3 = 0.84
 0.84 × 2 = 1.68  a-4 = 1 et R4 = 0.68
 0.68 × 2 = 1.36  a-5 = 1 et R5 = 0.36
 0.36 × 2 = 0.72  a-6 = 0 et R6 = 0.72
 0.72 × 2 = 1.44  a-7 = 1 et R7 = 0.44
Therefore : 0.2310 = 0.0011101…2: Infinite number of bits.
Typically, we take 4 or 5 bits or as many as available bits
S. Lahouar
26 Real numbers: fixed-point representation
A fixed number of bits n is used to represent the integer part and a fixed
number of bits m is used to represent the decimal part
Examples: Represent 15.25 and 0.23 using fixed-point representation with
n=4 bits for the integer part and m=4 bits for the decimal part:
 15.2510 = (1111.01)2=(11110100)FP4,4
 0.2310 = (0.0011101)2=(00000011)FP4,4
Drawbacks: since n and m are fixed, it’s difficult to represent with this
format big numbers and small numbers at the same time.
 15.25: even though the decimal part has 2 bits 0 at the end, we can’t
use these bits to represent bigger numbers in the integer part: we are
limited to 15, which is 11112
 0.23: even though the integer part is 0, we can’t use it to represent the
decimal part more accurately. In fact, we used only the first 4 bits of
the decimal part, and we ignored the rest
S. Lahouar
27 Real numbers: Floating-point representation
A number R is represented in a floating-point format as:

R=(-1)S × 1.M × 2e
with:
 S: sign bit (0R Positive and 1R Negative)
 M: mantissa: represents the bits after the decimal point
 e: exponent: represents the position of the decimal point in R

Examples:
 15.2510 = 1111.012 = (-1)0 × 1.11101 × 23  S=0, M=11101, e=3

 -0.875=-0.1112 = (-1)1 × 1.11 × 2-1  S=1, M=11, e=-1

S. Lahouar
28 Standard representation IEEE 754 single precision (FLOAT)

 It’s a standard floating-point representation that uses 32 bits to


represent the numbers
 In this representation the 32 bits are organized as follows:

S: 1 bit E: 8 bits M: 23 bits

with E=e+127: biased exponent. It’s used to avoid negative


values of e (i.e., E is always >0)
 The ‘1’ in 1.M is not stored in the 32 bits (it’s hidden)
 With FLOAT, the smallest number represented is 1.17×10-38 and
the largest number is 3.4×1038

S. Lahouar
29 Standard representation IEEE 754 single precision (FLOAT)

Examples:
 0.7510=0.112=(-1)0 × 1.1 × 2-1  S=0 ; M=1 ; e=-1 
E=e+127=126=011111102
FLOAT: 0.7510= 0 01111110 10000000000000000000000

S: 1 bit E: 8 bits M: 23 bits

 -2345.12510=-100100101001.0012=(-1)1 × 1. 00100101001001 × 211 


S=1 ; M=00100101001001 ; e=11  E=e+127=138=100010102
FLOAT: -2345.12510= 1 10001010 00100101001001000000000
S: 1 bit E: 8 bits M: 23 bits

S. Lahouar
30 Standard representation IEEE 754 double precision(DOUBLE)

 It’s a standard floating-point representation that uses 64 bits to


represent the numbers
 In this representation the 64 bits are organized as follows:

S: 1 bit E: 11 bits M: 52 bits

with E=e+1023: biased exponent. It’s used to avoid negative


values of e (i.e., E is always >0)
 With FLOAT, the smallest number represented is 2.23×10-308 and
the largest number is 1.8×10308

S. Lahouar
31 Standard representation IEEE 754 double precision(DOUBLE)

Examples:
 0.7510=0.112=(-1)0 × 2-1 × 1.1  S=0 ; M=1 ; e=-1 
E=e+1023=1022= 011111111102
Double: 0.7510= 0 01111111110 10000000000000000000…0

S: 1 bit E: 11 bits M: 52 bits

 -2345.12510=-100100101001.0012=(-1)1 × 211 × 1. 00100101001001 


S=1 ; M=00100101001001 ; e=11  E=e+1023=1034=100000010102
Double: -2345.12510= 1 10000001010 0010010100100100000…0
S: 1 bit E: 11 bits M: 52 bits

S. Lahouar
32 IEEE 754 standard representations: Special numbers

S. Lahouar
33 Addition in binary (1)
For 1 bit, the addition is performed as follows:
0+0 = 0 0+1 = 1 1+0 = 1 1+1 = 10: (1: Carry)
For multiple bits, the bits at the same order are added
together along with the Carry (if present)
The sum of 2 numbers of n bits each is written using
n+1 bits.

S. Lahouar
34 Addition in binary (2)
Examples:
1 1 1 1 1 1 1 1 1 1
0011 11111 111101
+ + +
0101 10101 011110
1000 110100 1011011

S. Lahouar
35 Binary subtraction (1)
 The subtraction of 2 binary numbers (a-b) is performed by
adding C2(b) to a  Addition:

a-b=a+C2(b)= a+C1(b)+1

 Subtraction algorithm:
Add C2(b) to a
Check if there is an overflow:
Case of an extra bit: ignore the extra bit. The number found (positive
in this case) is the result of a-b.
Case of no extra bit: the result of a-b is negative. The polynomial
could be applied to find the decimal equivalent.

S. Lahouar
Binary subtraction (2)
36
Examples: for n=5 bits:
 910-510 = ?  (0 1001)2 – (0 0101)2 = ?
 C2(0 0101) = 1 1011  0 1001+1 1011 = 1 0 0100
 Extra bit (6 bits): ignored
 The result is positive and correct: (0 0100)2=4
 510-910 = ?  (0 0101)2 – (0 1001)2 = ?
 C2(0 1001) = 1 0111  0 0101+1 0111 = 1 1100
 No extra bit (5 bits)
 The result is negative and correct  (1 1100)2 =-16+8+4=-4
 -910-510 = ?  C2(0 1001)+C2(0 0101) = ?
 1 0111+ 1 1011 =1 1 0010
 Extra bit (6 bits) ignored  The result is negative and correct: 1 0010=-16+2=-14
 -910-910 = ?  C2(0 1001)+C2(0 1001) = ?
 1 0111+ 1 0111 =1 0 1110
 Extra bit (6 bits) ignored  The result is positive and incorrect : 0 1110: We have
an overflow (the result can’t be written with 5 bits)
 910+910 = ?  (0 1001)2+(0 1001)2 = 1 0010
 No extra bit. The result is negative and incorrect : 1 0010: We have an overflow
(the result can’t be written with 5 bits)
S. Lahouar
37 Hex Addition/Subtraction
Addition/Subtraction performed digit by digit
Addition: there is a carry if the result> F ⇒ Carry should be
added to next digit
Subtraction: there is a borrow if b>a while calculating a-b
Examples:
1 1 1 1
A39 F53C F53C
+ + - 1
1AB A2C4 A24 B
BE4 1 98 0 0 52F1

S. Lahouar
38 Addition of 2 floating-point numbers
Calculate: A+B=(-1)Sa MA2Ea+(-1)Sb MB2Eb
This computation is done in the computer by the FPU
(Floating Point Unit) and not the microprocessor
Algorithm:
Align MA and MB according to Ea > Eb or Ea < Eb
Find the sum of the aligned mantissas (if A or B < 0, the C2
should be used instead of the number)
Normalize the result under the form (-1)S 1.M x 2e

S. Lahouar
39 Addition of 2 floating-point numbers: Example
Find the sum of A = 1.1*22 and B = 1.1011*23
A+B = 1.1*22 + 1.1011*23
Computation steps:
Alignment of the mantissas based on the largest
exponent (3 in this case) ⇒ A = 0.11*23
Therefore: A+B = (0.11+1.1011)*23
Sum of the aligned mantissas: 0.11+1.1011=10.0111
Normalization: A+B=10.0111 * 23 =1.00111 * 24

S. Lahouar
40 Multiplication of 2 floating-point numbers
Calculate: A x B = (-1)Sa MA2Ea x (-1)Sb MB2Eb
⇒ A x B = (-1)Sa+Sb (MA*MB) 2Ea+Eb
This computation is done in the computer by the FPU
(Floating Point Unit) and not the microprocessor
Algorithm:
Calculate the sign of the result: (-1)Sa+Sb
Calculate (MA*MB) and (Ea+Eb)
Normalize the result under the form 1.M x 2e

S. Lahouar
41 Multiplication of 2 floating-point numbers
Find the product of A = 1.1*22 and B = 1.1011*23
A*B = 1.1*22 * 1.1011*23
Therefore: A*B= 1.1 * 1.1011 * 22+3
Computation steps: 1.1011
* 1.1
Calculate: MA*MB=10.10001
+1 11011
1 1 1

Calculate: Ea+Eb=2+3=5 11011


Normalize the result: = 10.10001
A*B=10.10001*25=1.010001*26

S. Lahouar
42 Units used in binary

 1 bit ⇒ 1 Unit = 0 or 1

 1 Byte = 8 bits

 1 kByte = 1kB = 210 Bytes = 1024 Bytes

 1 MByte = 1MB = 210 kB = 1024 kB = 220 Bytes

 1 GByte = 1GB = 210 MB = 1024 MB = 230 Bytes

 1 TByte = 1 TB = 210 TB = 1024 GB = 240 Bytes

Note: N kbit = (N/8) kBytes

S. Lahouar
43 Binary Coding
 Binary Coding is the operation of attributing a group of bits to
numeric or alphanumeric values according to the required
application
 The objective of Binary Coding is to be able to store and process
information, in binary format, on a Computer
 There are many types of binary codes that are used for different
applications:
 Natural Binary Coding
 BCD Coding
 Gray Coding
 ASCII Coding
 Error detection and correction Coding
 ….

S. Lahouar
44 Binary Coded Decimal: BCD

In BCD, each decimal digit is coded in binary using 4 bits:

Examples: (Natural binary code is given for comparison)


 (0)10 = (0000)BCD = (0)2
 (1)10= (0001)BCD = (1)2
 (2)10= (0010)BCD = (10)2
 (9)10= (1001)BCD = (1001)2
 (10)10= (0001 0000)BCD = (1010)2
 (11)10= (0001 0001)BCD = (1011)2
 (125)10 = (0001 0010 0101)BCD= (1111101)2
 (29.375)10 = (0010 1001.0011 0111 0101)BCD = (11101.011)2

S. Lahouar
45 ASCII Coding

 ASCII: American Standard Code for Information Interchange


 It’s a coding used to transfer data between 2 machines (ex.
between PC and printer or between 2 PCs).
 ASCII encodes each letter (uppercase and lowercase) and
each digit with a unique value (ex. A=65, a=97, 0=48)
 The ASCII table contains also arithmetic operators (ex. +=43,
*=42)
 It contains also drawing characters (ex. 187= ╗, 188= ╝)
 And special commands to control the receiving machine (ex.
LF=10 : Line Feed, FF=12 : Form Feed, CR=13 : Carriage Return)
 The ASCII table contains 256 characters; therefore, each value is
represented by 8 bits.
S. Lahouar
46

S. Lahouar

You might also like