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

Chapter 1 - Number Systems PDF

Uploaded by

mariainesraheb08
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)
23 views72 pages

Chapter 1 - Number Systems PDF

Uploaded by

mariainesraheb08
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

Digital systems

Chapter 01

1 Number systems
Dr. Iness NEDJI MILAT
[email protected]

First year – 2024/2025


2 Digital systems
 Digital system is a combination of devices (most often electronic) designed to
manipulate information that are represented in digital form (discrete values).

 Some of the more familiar digital systems include digital computers

 Information processed by computer can be on different formats : number, text,


image, audio, video

 All these formats are represented in numeric values (number systems),

 In computer, they are always coded in binary form (BIT: BinarydigIT),

 Bits : sequence of 0 and 1.


3 Bits : Binary digITs
 Computer systems do not represent numeric values using the decimal system
but using binary system.

 Computers are built around the idea of two states : true (1) and false (0).

 Transistors represent this in hardware, Source Drain


and bits represent this in software! Gate Gate
Drain Source
pMOS nMOS
 Bit (Binary digIT) is represented by two voltage levels, where any voltage
between 0 and 0.2 V represents a 0 and any voltage between 0,9 and 1,1 V
represents a 1.
4 Number systems: generalization
 All data in digital systems are represented in number systems. The most common
are the decimal (10), binary (2), octal (8), and hexadecimal (16) systems.
 These systems are said positional number systems. Each number is represented by a
string of digits in which each digit has a position and a weight.
 The general form of a number X in such a system with base b (radix) is:
(X)b = ( dn-1dn-2 ... d1d0 . d-1 d-2 ... d-(m-1) d-m )b
Integer Fraction
 The decimal Value of X :
Val(X)10 = dn–1× b n–1 + dn–2× b n–2 + … + d1× b1 + d0 × b0 + d–1 × b–1 + d–2 × b–2 + … + d-m × b-m
position
= Ʃ di × b i
Weight

 (11011.01)2 = 1×24 + 1×23 + 0×22 + 1×2 + 1 + 0×2-1 + 1×2-2 = (27.25)10


 (156.7)8 = (1x82 + 5x81 + 6x80 + 7x8-1 )10 = (64 + 40 + 6 + 0.875)10 = (110.875)10
5 Decimal System : base 10
 The decimal system is called the base (radix)10 system because it has 10 digits
(0,1,2,3,4,5,6,7,8,9)
 The decimal system is a positional-value system in which the value of a digit
depends on its position.
msd lsd
For example :
Positional value 2 7 4 5
Weights : 10x 103 102 101 100

The 2 carries the most weight; it is referred to as the most significant digit (msd).The 5
carries the least weight and is called the least significant digit (lsd).

2745= 2*103 + 7*102 + 4*101 + 5*100 (Polynomial representation)


2745.214 = 2*103 + 7*102 + 4*101 + 5*100 + 2*10-1 + 1*10-2 + 4*10-3
6 Binary system: Base 2
 The Binary Number System uses base (radix) 2.
 It includes the digits 0 and 1.
 For example:
Most significant bit (msb) Least significant bit (lsb)

1101
Positional value
Weights: 2x 23 2 2 21 2 0

(1101)2 = 1*23 + 1*22 + 0*21 + 1*20 = 8 + 4 + 0 +1 = 1310


(1011.101)2 = 23 + 21 + 20 + 2-1 + 2-3
7 Octal and hexadecimal systems (1)
 When working with bits, oftentimes we have strings with 32 or 64 bits
(a large number of bits!!).
 So, it is more convenient and less error-prone to write the binary
numbers in intermediate base systems such as Octal (base 8) or
Hexadecimal systems (base 16),
 Octal and Hex are often used in a digital system as sort of a
“shorthand” way, more compact, to represent strings of bits.
 However, it is important to keep in mind that digital circuits all work in
binary.
 Octal and Hex are simply used as a convenience for the humans
involved.
8 Octal and hexadecimal systems (2)
 Base 8 (octal) numbers : 0,1,2,3,4,5,6,7
 one octal digit is formed by grouping 3 bits.
1000010101102 = 100 001 010 110
= 4 1 2 6 8

 Base 16 (Hexadecimal) is most useful as a “shorthand” notation for binary


numbers.
 Hex numbers : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
 one hexadecimal digit is formed by grouping 4 bits and start with 0x

1000010101102 = 1000 0101 0110


= 8 5 6 16

= 0x 856
9
Counting . . . 2, 8, 10, 16
Decimal Binary Octal Hexadecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
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
15 1111 17 F
16 10000 20 10
10 Word vs Byte vs Nibble?
 Word is a larger group of bits, typically 16, 32, or 64 bits. The size of a word
depends on the computer architecture,
Word (32 bits)

10100001000001011110101101001101
msb lsb

Byte Nibble (Half-byte)


(a group of 8bits) (a group of 4bits)

10100001 00000101 11101011 01001101


 The word contains the data that can be processed in a single operation.
 For example, a 32-bit computer can process 32-bit words at a time.
11 Memory capacity
 Memory capacity is usually measured in bytes.
 Binary size measure units :
12 Conversion from/to base x
13 Converting To and From Decimal

Decimal10
0123456789
Successive Weighted
Division Multiplication
Weighted Successive
Multiplication Division

Successive Weighted
Division Multiplication

Octal8 Hexadecimal16
01234567 0123456789ABCDEF

Binary2
01
14 From base X to Decimal Conversion

 Any number in base 2, 8 or 16 can be converted to its decimal equivalent by


multiplying each digit by its positional weight.

(11010) 2 = 1 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 0 * 20 = (26)10

(127.4) 8 = 1 * 82 + 2 * 81 + 7 * 80 + 4 * 8-1 = (87.5)10

(B65F)16 = 11 * 163 + 6 * 162 + 5 * 161 + 15 * 160 = (46687)10


15 Decimal to Binary Conversion : Integer
Repeated Division Method Example

• Divide the decimal number by 2.  Convert to binary (139)10


139 2
• Write the remainder after each
69 2
division until a quotient of zero is lsb 1
34 2
obtained. 1
17 2
0
• The first remainder is the lsb.
8 2
1
• The last is the msb. 4 2
0
2 2
(139)10=(10001011)2 0
1 2
0
0
msb 1
16 Decimal to Binary Conversion : Fraction
 Repeated Multiplication Method  Example

• Multiply the fractional part by 2. • Convert to the binary 0.8110


0.1 1 0 0 112
• The digit to the left of the decimal
0.81 x 2 = 1.62
point in the product will be 0 or 1 and
contributes to the binary 0.62 x 2 = 1.24
representation, 0.24 x 2 = 0.48
• The fractional part of the product is 0.48 x 2 = 0.96
used as the multiplicand in the next 0.96 x 2 = 1.92
step.
0.92 x 2 = 1.84

= 0.1100112 (approximately)
17 Decimal to Octal/Hex Conversion
A decimal can be converted to octal (resp. hexadecimal) by using the same
repeated-division method that used in binary conversion, but with a division factor
of 8 (resp. 16) instead 2,

 Example

266 = (412)8 423 = (1A7)16 = 0x1A7

266 8 423 16

33 8 26 16
2 7
4 8 1 16
1 10
0 1 0
4
18 Binary and Octal conversions
Octal to Binary Binary to Octal

 Replace each octal digit with its  Make groups of 3 bits, starting from
equivalent 3-bit binary sequence. the binary point.
 Example:  Add 0s to the ends of the number if
needed.
 Convert each bit group to its
261.358 = 2 6 1 . 3 58
corresponding octal digit.
= 010 110 001 . 011 1012
 Example :

10110100.0010112 = 010 110 100. 001 011 2


= 2 6 4 . 1 3 8
19
Binary and Hex conversions
Hexadecimal to Binary Binary to Hexadecimal
 Replace each hex digit with its  Make groups of 4 bits, starting from
equivalent 4-bit binary sequence. the binary point.
 Example:  Add 0s to the ends of the number if
needed.

261.3516 = 2 6 1 . 3 516
 Convert each bit group to its
= 0010 0110 0001 . 0011 01012
corresponding hex digit.
 Example :
10110100.0010112 = 1011 0100. 0010 11002
= B 4 . 2 C16
Hex Binary Hex Binary Hex Binary Hex Binary
0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111
20 Computer arithmetic
21 Types of decimal numbers
 Computer arithmetic is commonly performed on two very different types of
numbers: integer and real numbers.

Unsigned : 0, 1, 2, 3,,,,
Integer
Signed : ....,-2, -1, 0, +1, +2,....
Decimal number

Fixed-point : 3.14 more used


Real

Floating-point : 3.14 = 31.4 * 10-1 = 0.0314 * 102

 In both cases, the representation chosen is a crucial design issue and is


treated first, then the arithmetic operations.
22 Unsigned integer representation
 The representation of an unsigned integer number is a true binary form,
 Exemple : (139)10=(10001011)2

 Range of values :
 In digital computers, the range of unsigned numbers that can be represented is based
on the number of bits available in the hardware structures that store and process
information.

 What is the total range of unsigned decimal values that can be represented in a single
byte (8 bits)?
Minimum number = 0000 0000 = 0
Maximum number = 1111 1111 = 255
Method 1: 1*27 + 1*26 + 1*25 + 1*24 + 1*23+ 1*22 + 1*21 + 1*20 = 255
Method 2: 28 – 1 = 255
 The range of values for n bits is [0, 2n – 1]
23 Binary Addition
 The elementary operations are:

0 0 1 1 1
1
+ 0 + 1 + 0 + 1 + 1
0 1 1 10 11
 Compute 103+ 85 Carry in
1 1 1 1 1 1 1
103 ⎯→ 0 1 1 0 0 1 1 1 1 1 1 1
+ 0 1 0 1 0 1 0 1 +
+ 85 ⎯→ 0 1 0 1

188 ⎯→ 1 0 1 1 1 1 0 0 1 0 1 0 0

Carry out
24 Binary Multiplication
 Multiplication involves the generation of partial products that are summed to
produce the final product.
 The partial products are easily defined. When the multiplier bit is 1, the partial
product is the multiplicand. When the multiplier bit is 0, the partial product is 0.
1011 x (1101)
1011 x (1000 + 100 + 0 + 1) x1011 Multiplicand
1011 x (1*23 + 1*22 + 0*21 + 1*20 ) x1101 Multiplier

1011 x (1 * 20) = 00001011 1011


1011 x (0 * 21) = 00000000 0000
+ Partial
1011 x (1 * 22) = 00101100 1011 products
1011 x (1 * 23) = 01011000 1011
 Note: need double length result 10001111
 The computerized multiplication of a binary number by 2n is accomplished by
shifting that number to the left n bits.
25
Binary Division
 Idea :
1. The bits of the dividend are examined from left to right,
2. If the set of bits examined represents a number greater than or equal to the
divisor, a 1 is placed in the quotient and the divisor is subtracted from the
partial dividend. Otherwise 0 is placed,
3. This process is repeated until the last bit of dividend,

Dividend 10110 11 Divisor


11
01 11 Quotient
1 01
Partial 11
Remainders
100
11
1 Remainder
26 Binary Subtraction
 The elementary operations are: Borrow
1
0 1 1 0
- 1
- 0 - 0 - 1 1
0 1 0 1
 Compute 103 - 85 Borrow
1
103 ⎯→ 0 1 1 0 0 1 1 1
- 0 11+0 1 0 1 0 1
- 85 ⎯→

18 ⎯→ 0 0 0 1 0 0 1 0
27 Binary Substraction
 How does the computer subtract two binary numbers?

5–3=?
0101 – 0011 = ? Materially, the sub circuit does not exist

Solution : use the adder circuit


 Subtraction is equivalent to addition with a negative number

5 + (-3) = ?
5 +? =?

How can we represent negative numbers?

Use a signed integer representation


How can we
28 Signed integer representation represent the sign
symbol ?

Unsigned : 0, 1, 2, 3,…
(139)10=(10001011)2
Integer
Negative (-139)10=(-10001011)2
Signed : ..,-2, -1, 0, +1, +2,..
Positive (+139)10=(+10001011)2

 Three methods to represent a signed integer

Sign/Magnitude
One’s complement

Two’s complement
Range of values

29 Sign/Magnitude Representation [- (2n-1 - 1), 2n-1 - 1]

 Let msb represent the sign (0=positive, 1=negative)


n bits
 and the remaining n-1 bits for magnitude
Sign Magnitude
 +7 = 0111 (4 bits) = 00000111 (8 bits)
msb
 - 7 = 1111 (4 bits) = 10000111 (8 bits) n -1 bits

Expansion of bits Move the sign bit to


the new leftmost position
 Problems : and fill in with zeros.
1. Two zero’s: +010 (00002) different than - 010 (10002)
2. Addition operation does not work correctly!

(+2)10 0 0 1 0
+ + 1 1 0 1
(- 5)10 ⎯→

(- 3)10 1 1 1 1 = - 710 Error !


Range of values
Sign/Magnitude Representation [- (2n-1 – 1), 2n-1 - 1]
30
Binary S/M Decimal

0000 0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -0
1001 -1
1010 -2
1011 -3
1100 -4
1101 -5
1110 -6
1111 -7
Range of values

31 One’s complement [- (2n-1 – 1), 2n-1 - 1]

 For positive numbers, 1’s complement is the same as the sign/magnitude


method (msb = 0 and the remaining n-1 bits for magnitude)

 The difference concerns the negative numbers that complement the positive
numbers

 Example: Expansion of bits Move the sign bit to the


new leftmost position and
 +7 = 0111 (4 bits) = 00000111 (8 bits) fill in with copies of the sign
 -7 = 1000 (4 bits) = 11111000 (8 bits) bit.

 Problem
 Two zero’s still: + 010 (00002) different than - 010 (11112)
Range of values
One’s complement [- (2n-1 – 1), 2n-1 - 1]
32
Binary 1’c Decimal
0000 0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -7
1001 -6
1010 -5
1011 -4
1100 -3
1101 -2
1110 -1
1111 -0
Range of values
33 Two’s complement [- 2n-1, 2n-1 - 1]

The 2’s complement system for representing signed numbers works like this:
 If the number is positive, the magnitude is represented in its true binary form (unsigned), and a
sign bit of 0 is placed in front of the msb.
+ 45 = 0 1 0 1 1 0 1
 If the number is negative, apply the following steps (2’c) : - 45 = ?
1. Obtain the bit pattern of absolute value (unsigned), 1 0 1 1 0 1 = 45
2. Check if the negative number can be represented 0 1 0 1 1 0 1
on the absolute value size (n=6 bits : range = [-32, 31])
otherwise insert 0 on the left (-45 ⸦ [-32, 31])
3. Invert the bit pattern (1’s complement),
1 0 1 0 0 1 0
+ 1
4. Add one to it.
1 0 1 0 0 1 1 = - 45
34 Two’s complement : examples
Add 0 on left because -9 needs 5 bits
❑ (-9)10 = (?)2 represented in 5 bits

(-9)10 = 2’s complement (9) = 2’s complement (01001)


= 10110 + 1 = 101112

❑ (10111)2 = (?)10
(10111)2 = - ( 2’s complement (10111))
negative
= - ( 01000 + 1)

= - ( 01001)

= - 910

❑ (00111)2 = (?)10
(00111)2 = + (1*22 + 1*21 + 1*20 )
positive
= + 710
35 4 bits Two’s complement signed integer
Binary 2’c Decimal

Only one number represent 0 0000 0


0001 1
0010 2
0011 3
Positive numbers
are represented as usual.
0100 4
0101 5
0110 6
Can represent one more
0111 7
negative number than
1000 -8 positive numbers.
1001 -7
1010 -6
All negative numbers Negative numbers are
1011 -5
have msb set (=1). This is listed in reverse order.
1100 -4
called the sign bit.
1101 -3
1110 -2
1111 -1
36 Signed vs Unsigned Number Wheels
37 Expansion of bit length
Representation : true binary form
Unsigned integer Range values : [0, 2n – 1] [0, 15] [0, 255]
0, 1, 2, 3.. Expansion : add 0 to the left
12 = 11002 (4 bits) 00001100 (8 bits)
Integer extend
Decimal
(n bits) Representation : 2’s complement
4 bits Range values : [- 2n-1, 2n-1 - 1] [- 8, 7] [-128, 127]
Signed integer
8 bits
.., -2, -1, 0, 1, 2,.. Expansion : add additional bits to the left and
fill in with the value of the sign bit
+ 6 = 0110 (4 bits) 00000110 (8 bits)
The only one extend
used by - 6 = 1010 (4 bits) 11111010 (8 bits)
default in the extend
38 Arithmetic Operations with Signed Numbers
 Rules for addition
 Use the signed number notation with negative numbers in 2’s
complement form

 Add the two signed numbers like unsigned numbers

 Discard any final carries (carry out).

 The result is in signed form.

00011110 = +30 00001110 = +14 11111111 = -1


+ + +
00001111 = +15 11101111 = -17 11111000 = -8
00101101 = +45 11111101= -3 111110111 = -9
32+8+4+1 - (00000010 + 1) - (00001000 + 1)
- (00000011) Discard carry out - (00001001)
Note that overflow can occur
Problem of overflow whether or not there is a carry out.

39
 Sometimes the addition result may be larger than can be held in given word
size (It exceeds the maximum value that can be represented in n bits),
 This case is called overflow (Problem).
 Example 1 : For 4-bit representation 0111 = +7
+
 1000 in two’s complement is - 8, not +8 0001 = +1
1000 = -X
8 WRONG
 Example 2: For 8-bit representation

01000000 = + 64 10000001 = -127


+ +
01000001 = + 65 Discard carry out 10000001 = -127
10000001 = -127 X 1 00000010 = +2X
 Oveflow occurs only when the signs of the operands are the same but the sign
of the result is different.
 The adder circuit must detect and signal the overflow exception to avoid the
use of an incorrect result of addition (the Operating system will fix this exception),
40 Real number representation
 Our decimal system handles Two types of real numbers :
This approach has
 Fixed point : limitations. Very large
 Using the decimal point (.) to make a fixed notation : numbers cannot be
represented, nor can
Real number =  ... d2d1d0 . d-1 d-2 ... very small fractions.
Integer Fraction

 Ex : 563.78 = 5 x 102 + 6 x 101 + 3 x 100 + 7 x 10-1 + 8 x 10-2

 Floating point (called also scientific notation) :


Ex : 563.78 = 5.6378 x 102
Real number =  Mantissa x 10 Exponent_value = 0.56378 x 103
= 5637.8 x 10-1
 Used to represent any real number even very large or very small ones with the
precision needed
 Unit of electric charge e = 1.602 x 10-19 Coulomb
 Volume of universe = 1 x 1085 cm3
41 Real number specifications
 4 specifications required for a decimal floating-point number :
1. Sign
2. Magnitude or Mantissa or Significand
3. Sign of the exponent
4. Magnitude of the exponent Decimal
 Plus floating-point
notation
5. Base of the exponent
6. Location of decimal point or other base point
Location of decimal point Sign of the exponent

Magnitude of the
- 13.25 = - 0.1325 x 10+2 Exponent

Sign of the mantissa Mantissa Base of the Exponent


42 Floating point representation
 Conversion from real decimal to binary number : The computer cannot
represent the extra
(-13.25)10= (-1101.01)2 symbols : sign, point

Use the binary floating point representation


 Mantissa x 2 Exponent_value
A number with this notation can be stored in computer with three fields :

Sign Exponent Mantissa

 The following representations are all the same in value :


 -1101.01 = - 11.0101  22 Problem
Several representations
= - 0.110101  2 4
equal to (-1101.01)2 !!!
= - 11010.1  2-1
 Solution : Floating point numbers should be normalized
43 Normalized Floating Point Numbers
 Idea of normalization:
 Exactly one non-zero bit (= 1) should appear before the point,
 Not Normalized: -1101.101×2–6
 Normalized: -1.101101×2–3
The value of the normalized floating point is :
 (1.F)2 × 2exponent_value

 For a normalized floating point number (according to the IEEE 754 standard):

S E F = f1 f2 f 3 f4 …
They are implicit
(ie, the same for
 S = 0 is positive, S = 1 is negative all numbers)
 Mantissa (Significand) is equal to (1.F)2 = (1.f1f2f3f4…)2
 IEEE 754 assumes hidden 1. (not stored) for normalized numbers
44 Conversion to floating-point representation
 We mimic the decimal floating point notation to create the binary floating point
number:
1. We first convert the real number to its binary form. We use a “binary point” to
separate integer part from fractional part of the number to make a fixed point
notation:
 Ex: -13.25 = (-1101.01)2
2. We then “float” the binary point (normalization to the binary floating point notation):
 - 1101.01 => -(1.10101)2 x 23 (Sign = 1, mantissa = 1.10101, exponent_value = +3)

3. Now we have to express this number without the extra symbols ( -, x, 2, point )
 by convention, we divide the available bits into three fields: sign, exponent, fraction

sign exponent fraction


45 IEEE 754 Floating-Point Standard

 We have two types of floating-point representation :


 Single Precision Floating Point Numbers (32 bits)
 1bit sign + 8bits exponent + 23bits fraction

S Exponent (8bits) Fraction (23 bits)

 Double Precision Floating Point Numbers (64 bits)


 1bit sign + 11bits exponent + 52bits fraction

S Exponent (11bits) Fraction (52 bits)


46 Exponent Representation
 (1.F)2 × 2 exponent_value

 How to represent a signed exponent_value?


 Two’s complement representation,
 Biased representation

 IEEE 754 uses biased representation for the exponent_value


 Exponent_value = E – Bias (Bias is a constant)
 E = Exponent_value + Bias

 Typically, Bias = 2k-1 -1 (k is the size of exponent field (E))


 Single precision : Bias = 28-1 -1 = 127

 Double precision : Bias = 211-1 -1 = 1023


47 Biased Exponent
 Single precision
 The exponent field is 8 bits
 E = 0 and E = 255 are reserved for special use
 E = 1 to 254 are used for normalized floating point numbers
 Bias = 127 (half of 254)
 Exponent value = E – 127 Range: -126 to +127

 Double precision
 The exponent field is 11 bits
 E = 0 and E = 2047 are reserved for special use
 E = 1 to 2046 are used for normalized floating point numbers
 Bias = 1023 (half of 2046)
 Exponent value = E – 1023Range: -1022 to +1023
48 Summary of IEEE 754 Encoding
Single-Precision Exponent = 8 Fraction = 23 Value
Normalized Number 1 to 254 Anything ± (1.F)2 × 2E – 127
Denormalized Number 0 nonzero ± (0.F)2 × 2–126
Zero 0 0 ±0
Infinity 255 0 ±∞
NaN (not a Number) 255 nonzero NaN

Double-Precision Exponent = 11 Fraction = 52 Value


Normalized Number 1 to 2046 Anything ± (1.F)2 × 2E – 1023
Denormalized Number 0 nonzero ± (0.F)2 × 2–1022
Zero 0 0 ±0
Infinity 2047 0 ±∞
NaN 2047 nonzero NaN
49 Examples of Single Precision Float
 What is the decimal value of this Single Precision float?

10111110001000000000000000000000
 Solution:
 Sign = 1 is negative
 E = (01111100)2 = 124, Exponent-value = E – bias = 124 – 127 = –3
 Significand = (1.0100 … 0)2 = 1*20 + 1*2-2 = 1.25 (1. is implicit)
 Value in decimal = - 1.01 x 2–3 = - (0.00101)2 = - (2–3 + 2–5) = – 0.15625
= - 1.25 × 2–3 = – 0.15625

 What is the decimal value of?


01000001001001100000000000000000
 Solution: implicit
 Value in decimal = +(1.01001100 … 0)2 × 2130–127
(1.01001100 … 0)2 × 23 = (1010.01100 … 0)2 = 10.375
50
Examples of Double Precision Float
 What is the decimal value of this Double Precision float ?
01000000010100101010000000000000
00000000000000000000000000000000

 Solution:
 Value of exponent = (10000000101)2 – Bias = 1029 – 1023 = 6
 Value of double = (1.00101010 … 0)2 × 26 (1. is implicit)
= (1001010.10 … 0)2 = 74.5

 What is the decimal value of ?


10111111100010000000000000000000
00000000000000000000000000000000

 Do it yourself! (answer should be –1.5 × 2–7 = – 0.01171875)


51 Decimal to Binary Floating-Point
 Convert - 0.8125 to single and double-precision floating-point
 Solution:
 Fraction bits can be obtained using multiplication by 2
 0.8125 × 2= 1.625
 0.625 × 2 = 1.25
0.8125 = (0.1101)2
 0.25 × 2 = 0.5
 0.5 × 2 = 1.0
 Stop when fractional part is 0, or after computing all required fraction bits
 - 0.8125 = - (0.1101)2 = - (1.101)2 × 2 –1 (Normalized)
 E = –1 + Bias = 126 (single precision) and 1022 (double)
Single
10111111010100000000000000000000 Precision
10111111111010100000000000000000 Double
Precision
00000000000000000000000000000000
52 Other codes
53 Binary Coded Decimal (BCD)
 The Binary Coded Decimal (BCD) is the simplest binary code. It’s an easier way to
represent decimal number in digital systems for displaying them in digital diplays.

 In this binary representation each decimal digit


is converted to its 4-bit pure binary equivalent

 It only encodes the first ten values from 0 to 9.

 For example: (57)10 ➔ (?) bcd

( 5 7 ) 10 = (0101 0111) bcd


Coding
( 5 7 ) 10 = (111001) 2 (unsigned)
Converting
54 BCD addition = 13 > 9
Not BCD code !!
(sol : add 6)
 Add the following BCD numbers :
 0110 0111 + 0010 0001
 0011 0110 + 0101 0111

1 1 1 1 1 1 1 1 1 1

67 ⎯→ 0 1 1 0 0 1 1 1 36 ⎯→ 0 0 1 1 0 1 1 0
+ +
+ 21 0 0 1 0 0 0 0 1 + 57 ⎯→ 0 1 0 1 0 1 1 1
⎯→
1 1
1 0 0 0 1 0 0 0 93 1 0 0 0 1 1 0 1
88
0 1 1 0

1 0 0 1 0 0 1 1
55 Gray code
 The Gray code is a binary code used in applications where numbers
change rapidly (Ex. : position sensors in the mouse).
 In Gray code, only one bit changes from each value to the next.
 This allows to avoid problems in systems where an error can occur if more
than one bit changes at a time

Three bit binary


and Gray code
equivalents.
56 Binary to Gray code
 (110101) 2 = (?)Gray

Binary 1 1 0 1 0 1
msb

Gray 1
msb
57 Binary to Gray code
Same → 0
 (110101) 2 = (?)Gray Different → 1

Binary 1 1 0 1 0 1
msb

Gray 1 0
msb
58 Binary to Gray code
Same → 0
 (110101) 2 = (?)Gray Different → 1

Binary 1 1 0 1 0 1
msb

Gray 1 0 1
msb
59 Binary to Gray code
Same → 0
Different → 1
 (110101) 2 = (?)Gray

Binary 1 1 0 1 0 1
msb

Gray 1 0 1 1
msb
60 Binary to Gray code
Same → 0
 (110101) 2 = (?)Gray Different → 1

Binary 1 1 0 1 0 1
msb

Gray 1 0 1 1 1
msb
61 Binary to Gray code
Same → 0
 (110101) 2 = (?)Gray Different → 1

Binary 1 1 0 1 0 1
msb

Gray 1 0 1 1 1 1
msb

 (110101) 2= (101111)Gray
62 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb

Binary 1
msb
63 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb

Same → 0
Different → 1

Binary 1 1
msb
64 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb

Same → 0
Different → 1

Binary 11 0
msb
65 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb

Same → 0
Different → 1

Binary 11 0 1
msb
66 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb
Same → 0
Different → 1

Binary 11 0 1 0
msb
67 Gray to Binary
 (101111) Gray = (?) 2

Gray 1 0 1 1 1 1
msb Same → 0
Different → 1

Binary 11 0 1 0 1
msb

 (101111)Gray = (110101) 2
68 Decimal-Binary-Hex-BCD-Gray

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
All rights reserved.
69 ASCII (American Standard Code for Information Interchange)
 The ASCII code is a character encoding standard,
 It assigns a unique numerical code to each character, including :
 Letters (A-Z, a-z),
 Numbers (0-9),
 Punctuation marks (!,?,:,...), and
 Control characters (tab, escape, carriage return (CR),...)
 Each character is represented by a 7-bit binary code, which allows for a total of
128 unique characters (27 = 128 possible codes),
 The ASCII code allows computers to store, process, and transmit text data.

 Extension: In 1981, IBM introduced extended ASCII, which is an 8-bits code and
increased the character set to 256
Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
All rights reserved.
ASCII code
70
71 UNICODE
 UNICODE is also a character encoding standard. However, it differs from ASCII
code in their scope and capabilities.

 UNICODE extends ASCII to 65536 universal characters codes,

 It includes characters from many different languages, including English, Arabic,


Chinese, Japanese, Hindi, and many others.

 UNICODE uses 16 bits (UTF-16) or 32 bits (UTF-32) to represent each character,


allowing for millions of unique characters.

 It is available in many modern applications


72 Conversion or Coding?
 Do NOT mix up conversion of a decimal number to a binary number with
coding a decimal number with a binary code.

 The conversion yields the exact numerical value (i.e. it involves directly
translating the decimal number into its equivalent binary representation

 The coding provides a symbolic representation based on a coding scheme like


BCD, Gray,..
 Example :
 1310 = 11012
This is conversion
 1310 = 0001 0011BCD
This is coding

You might also like