0% found this document useful (0 votes)
5 views

bu_logic_01

The document outlines a course on Digital Logic, covering topics such as number systems, binary logic, circuit optimization, and memory basics. It includes detailed sections on combinational and sequential circuits, as well as implementation technologies. The course aims to provide a comprehensive understanding of digital systems and their design principles.

Uploaded by

Abed Sabbagh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

bu_logic_01

The document outlines a course on Digital Logic, covering topics such as number systems, binary logic, circuit optimization, and memory basics. It includes detailed sections on combinational and sequential circuits, as well as implementation technologies. The course aims to provide a comprehensive understanding of digital systems and their design principles.

Uploaded by

Abed Sabbagh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to Digital Logic Course Outline

1. Digital Computers, Number Systems, Arithmetic Operations, Decimal,


Alphanumeric, and Gray Codes
2. Binary Logic, Gates, Boolean Algebra, Standard Forms
3. Circuit Optimization, Two-Level Optimization, Map Manipulation, Multi-Level
Prof. Nizamettin AYDIN Circuit Optimization
4. Additional Gates and Circuits, Other Gate Types, Exclusive-OR Operator and Gates,
High-Impedance Outputs
5. Implementation Technology and Logic Design, Design Concepts and Automation,
The Design Space, Design Procedure, The major design steps
[email protected] 6. Programmable Implementation Technologies: Read-Only Memories, Programmable
Logic Arrays, Programmable Array Logic,Technology mapping to programmable
[email protected] 7.
logic devices
Combinational Functions and Circuits
8. Arithmetic Functions and Circuits
9. Sequential Circuits Storage Elements and Sequential Circuit Analysis
10. Sequential Circuits, Sequential Circuit Design State Diagrams, State Tables
11. Counters, register cells, buses, & serial operations
12. Sequencing and Control, Datapath and Control, Algorithmic State Machines (ASM)
13. Memory Basics

1 2

Introduction to Digital Logic Overview


• Digital Systems and Computer Systems
• Information Representation
Lecture 1 • Number Systems [binary, octal and hexadecimal]
• Arithmetic Operations
Digital Computers and
• Base Conversion
Information • Decimal Codes [BCD (binary coded decimal), parity]
• Gray Codes
• Alphanumeric Codes

3 4

The Computer Level Hierarchy Digital System


• Takes a set of discrete information (inputs) and
• Each virtual machine
layer is an abstraction of
discrete internal information (system state) and
the level below it. generates a set of discrete information (outputs).
• The machines at each
level execute their own Discrete
particular instructions, Discrete
Inputs Information
calling upon machines at Discrete
lower levels to perform
Processing
System Outputs
tasks as required.
• Computer circuits
ultimately carry out the
work.
System State

5 6

Copyright 2000 N. AYDIN. All rights


reserved. 1
Types of Digital Systems Digital System Example:
• No state present
– Combinational Logic System A Digital Counter
– Output = Function (Input)
• State present Count Up
– State updated at discrete times Reset 0 0 1 3 5 6 4
=> Synchronous Sequential System
– State updated at any time Inputs: Count Up, Reset
=>Asynchronous Sequential System Outputs: Visual Display
– State = Function (State, Input) State: "Value" of stored digits
– Output = Function (State)
or Function (State, Input)
Synchronous or Asynchronous?

7 8

A Digital Computer Example Signal

Memory
• An information variable represented by physical
quantity.
• For digital systems, the variable takes on discrete
values.
Control • Two level, or binary values are the most prevalent
CPU unit Datapath values in digital systems.
• Binary values are represented abstractly by:
Inputs: – digits 0 and 1
Outputs: CRT,
Keyboard, – words (symbols) False (F) and True (T)
LCD, modem,
mouse, modem, Input/Output – words (symbols) Low (L) and High (H)
speakers – and words On and Off.
microphone
Synchronous or • Binary values are represented by values or ranges of
values of physical quantities
Asynchronous?
9 10

Signal Examples Over Time Signal Example – Physical Quantity: Voltage

Time OUTPUT INPUT


Continuous 5.0
in value & HIGH HIGH
Analog 4.0
time
3.0
Digital Discrete in Threshold
value & 2.0 Region
Asynchronous continuous
1.0
in time LOW LOW
Discrete in
0.0
Synchronous
value & time Volts
11 12

Copyright 2000 N. AYDIN. All rights


reserved. 2
Binary Values: Other Physical Quantities Number Systems – Representation

• What are other physical quantities • Positive radix, positional number systems
represent 0 and 1? • A number with radix r is represented by a
string of digits:
– CPU Voltage A n - 1A n - 2 … A 1A 0 . A - 1 A - 2 … A - m + 1 A - m
– Disk Magnetic Field Direction in which 0 ≤ Ai < r and . is the radix point.
– CD Surface Pits/Light • The string of digits represents the power series:

(∑ ) (∑ )
j=-1
– Dynamic RAM Electrical Charge i=n-1
(Number)r = Ai r i + Aj r j
i=0 j=-m
(Integer Portion) + (Fraction Portion)
13 14

Number Systems – Examples Special Powers of 2


General Decimal Binary

Radix (Base) r 10 2

Digits 0 => r - 1 0 => 9 0 => 1  210 (1024) is Kilo, denoted "K"


0 r0 1 1

 220 (1,048,576) is Mega, denoted "M"


1 r1 10 2
2 r2 100 4
3 r3 1000 8

 230 (1,073, 741,824) is Giga, denoted "G"


Powers of 4 r4 10,000 16
Radix 5 r5 100,000 32
-1 r -1 0.1 0.5
-2 r -2 0.01 0.25
 240 (1,099,511,627,776) is Tera, denoted “T"
-3 r -3 0.001 0.125
-4 r -4 0.0001 0.0625
-5 r -5 0.00001 0.03125

15 16

Positive Powers of 2 Converting Binary to Decimal


• Useful for Base Conversion
• To convert to decimal, use decimal arithmetic
Exponent Value Exponent Value to form Σ (digit × respective power of 2).
0 1 11 2,048
1 2 12 4,096
• Example:Convert 110102 to N10:
2 4 13 8,192
3 8 14 16,384
4 16 15 32,768
5 32 16 65,536 ×24 + 1×
1× ×23 + 0×
×22 + 1×
×21 + 0×
×20 = 26
6 64 17 131,072
7 128 18 262,144
8 256 19 524,288
9 512 20 1,048,576
10 1024 21 2,097,152
17 18

Copyright 2000 N. AYDIN. All rights


reserved. 3
Converting Decimal to Binary Commonly Occurring Bases
• Method 1
– Subtract the largest power of 2 that gives a positive
remainder and record the power. Name Radix Digits
– Repeat, subtracting from the prior remainder and recording
the power, until the remainder is zero. Binary 2 0,1
– Place 1’s in the positions in the binary result corresponding
to the powers recorded; in all other positions place 0’s. Octal 8 0,1,2,3,4,5,6,7
• Example: Convert 62510 to N2
– 625 – 512 = 113 = N1 512 = 29 Decimal 10 0,1,2,3,4,5,6,7,8,9
– 113 – 64 = 49 = N2 64 = 26
– 49 – 32 = 17 = N3 32 = 25 Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
– 17 – 16 = 1 = N4 16 = 24
– 1 – 1 = 0 = N5 1 = 20  The six letters (in addition to the 10
integers) in hexadecimal represent:
(625)10 = 1⋅⋅29 + 0⋅⋅28 + 0⋅⋅27 + 1⋅⋅26 + 1⋅⋅25 + 1⋅⋅24 + 0⋅⋅23 + 0⋅⋅22 + 0⋅⋅21 + 1⋅⋅20

= (1001110001)2 →10, B→
A→ → 11, C→
→ 12, D→
→ 13, E→
→ 14, F→
→ 15
19 20

Numbers in Different Bases Conversion Between Bases


• Good idea to memorize!
Decimal
(Base 10)
Binary
(Base 2)
Octal
(Base 8)
Hexadecimal
(Base 16)
 Method 2
00
01
00000
00001
00
01
00
01
 To convert from one base to another:
02 00010 02 02
03 00011 03 03 1) Convert the Integer Part
04 00100 04 04
05
06
00101
00110
05
06
05
06
2) Convert the Fraction Part
07 00111 07 07
08 01000 10 08
3) Join the two results with a radix point
09 01001 11 09
10 01010 12 0A
11 01011 13 0B
12 01100 14 0C
13 01101 15 0D
14 01110 16 0E
15 01111 17 0F
16 10000 20 10

21 22

Conversion Details Example: Convert 46.687510 To Base 2

• To Convert the Integer Part: • Convert 46 to Base 2:


Repeatedly divide the number by the new radix and save – (101110)2
the remainders. The digits for the new radix are the
remainders in reverse order of their computation. If the
new radix is > 10, then convert all remainders > 10 to • Convert 0.6875 to Base 2:
digits A, B, …
– (0.1011)2
• To Convert the Fractional Part:
Repeatedly multiply the fraction by the new radix and
save the integer digits that result. The digits for the new • Join the results together with the radix
radix are the integer digits in order of their computation.
If the new radix is > 10, then convert all integers > 10 to point:
digits A, B, … – (101110.1011)2
23 24

Copyright 2000 N. AYDIN. All rights


reserved. 4
Additional Issue - Fractional Part Checking the Conversion
• Note that in the conversion in the previous slide, • To convert back, sum the digits times their
the fractional part became 0 as a result of the respective powers of r.
repeated multiplications. • From the prior conversion of 46.687510
• In general, it may take many bits to get this to 1011102 = 1⋅⋅25 + 0⋅⋅24 + 1⋅⋅23 + 1⋅⋅22 + 1⋅⋅21 + 0⋅⋅20
happen or it may never happen.
• Example: Convert 0.6510 to N2 =1·32 + 0·16 +1·8 +1·4 + 1·2 +0·1
– 0.65 = 0.1010011001001 …
= 32 + 8 + 4 + 2
– The fractional part begins repeating every 4 steps = 46
yielding repeating 1001 forever!
• Solution: ? 0.10112 = 1/2 + 1/8 + 1/16
– Specify number of bits to right of radix point and round = 0.5000 + 0.1250 + 0.0625
or truncate to this number. = 0.6875

25 26

Octal to Binary and Back Hexadecimal to Binary and Back


• Octal to Binary: • Hexadecimal to Binary:
– Restate the octal as three binary digits starting – Restate the hexadecimal as four binary digits
at the radix point and going both ways. starting at the radix point and going both ways.
• Binary to Octal: • Binary to Hexadecimal:
– Group the binary digits into three bit groups – Group the binary digits into four bit groups
starting at the radix point and going both ways, starting at the radix point and going both ways,
padding with zeros as needed in the fractional padding with zeros as needed in the fractional
part. part.
– Convert each group of three bits to an octal – Convert each group of four bits to a
digit. hexadecimal digit.

27 28

Octal to Hexadecimal via Binary A Final Conversion Note


• Convert octal to binary. • You can use arithmetic in other bases if you
• Use groups of four bits and convert as above to are careful:
hexadecimal digits.
• Example: Octal to Binary to Hexadecimal • Example: Convert 1011102 to Base 10 using
(6 3 5 . 1 7 7) 8 binary arithmetic:
(110 011 101 . 001 111 111)2 Step 1 101110 / 1010 = 100 r 0110
(0001 1001 1101 . 0011 1111 1000)2 Step 2 100 / 1010 = 0 r 0100
(1 9 D . 3 F 8)16 Converted Digits are 01002 | 01102
or (4 6) 10
• Why do these conversions work?

29 30

Copyright 2000 N. AYDIN. All rights


reserved. 5
Binary Numbers and Binary Coding Non-numeric Binary Codes
• Flexibility of representation
• Given n binary digits (called bits), a binary code
– Within constraints below, can assign any binary
combination (called a code word) to any data as long as is a mapping from a set of represented elements
data is uniquely encoded. to a subset of the 2n binary numbers.
• Information Types • Example: A Color Binary Number
– Numeric binary code Red 000
• Must represent range of data needed Orange 001
for the seven
• Very desirable to represent data such that simple, Yellow 010
straightforward computation for common arithmetic operations colors of the
permitted Green 011
rainbow Blue 101
• Tight relation to binary numbers
• Code 100 is Indigo 110
– Non-numeric Violet
not used 111
• Greater flexibility since arithmetic operations not applied.
• Not tied to binary numbers

31 32

Number of Bits Required Number of Elements Represented


S1-2-28Eylul

• Given M elements to be represented by a rn


• Given n digits in radix r, there are distinct
binary code, the minimum number of bits, elements that can be represented.
n, needed, satisfies the following • But, you can represent m elements, m < rn
relationships: • Examples:
2n > M > 2(n – 1)
n =log2 M where x , called the ceiling – You can represent 4 elements in radix r = 2 with
function, is the integer greater than or equal n = 2 digits: (00, 01, 10, 11).
to x. – You can represent 4 elements in radix r = 2 with
• Example: How many bits are required to n = 4 digits: (0001, 0010, 0100, 1000).
represent decimal digits with a binary code? – This second code is called a "one hot" code.
– 4 bits are required (n =log2 9 = 4)

33 34

Binary Codes for Decimal Digits Binary Coded Decimal (BCD)


The usual way of expressing a decimal number in terms of a binary
number is known as pure binary coding • In the 8421 Binary Coded Decimal (BCD)
There are over 8,000 ways that you can chose 10 elements from the 16
binary numbers of 4 bits. A few are useful:
representation each decimal digit is converted to
its 4-bit pure binary equivalent
Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray • This code is the simplest, most intuitive binary
0 0000 0011 0000 0000 code for decimal digits and uses the same powers
1 0001 0100 0111 0001
2 0010 0101 0110 0011 of 2 as a binary number, but only encodes the first
3 0011 0110 0101 0010 ten values from 0 to 9.
4 0100 0111 0100 0110
5 0101 1000 1011 0111 For example: (57)dec  (?) bcd
6 0110 1001 1010 0101
7 0111 1010 1001 0100 ( 5 7 ) dec
8 1000 1011 1000 1100 = (0101 0111)bcd
9 1001 1100 1111 1101

35 36

Copyright 2000 N. AYDIN. All rights


reserved. 6
Excess 3 Code and 8, 4, –2, –1 Code Binary to Gray Code Conversion
Decimal Excess 3 8, 4, –2, –1 Decimal 8421 Gray
0 0011 0000 • What special property does the 0 0000 0000
Gray code have in relation to 1 0001 0001
1 0100 0111 adjacent decimal digits?
2 0010 0011
• To convert binary to a Gray-
2 0101 0110 coded number then follow this 3 0011 0010
method : 4 0100 0110
3 0110 0101
1. The binary number and the 5 0101 0111
4 0111 0100 Gray-coded number will have
the same number of bits 6 0110 0101
5 1000 1011 2. The Gray code MSB (left-hand 7 0111 0100
bit) and binary MSB will 8 1000 1100
6 1001 1010 always be the same 9 1001 1101
7 1010 1001 3. To get the Gray code next-to-
MSB (i.e. next digit to the right) 10 1010 1111
8 1011 1000 add the binary MSB and the 11 1011 1110
binary next-to-MSB. Record 12 1100 1010
9 1100 1111 the sum, ignoring any carry.
4. Continue in this manner right 13 1101 1011
through to the end. 14 1110 1001
• What interesting property is common 15 1111 1000
to these two codes?
37 38

Gray Code to Binary conversion Binary to Gray Conversion Example


• Question: Convert the binary number 11101101 to its Gray code
Decimal 8421 Gray equivalent.
• To convert a Gray-coded 0 0000 0000 • Answer:
number to binary then follow 1 0001 0001
this method :
2 0010 0011
1. The binary number and the Binary 11101101 Gray CodeDigit 1 =1 (same as binary)
Gray-coded number will have 3 0011 0010
the same number of bits 4 0100 0110 Binary 11101101 Gray Code Digit 2 =1+1=0 (carry 1)
2. The binary MSB (left-hand bit) 5 0101 0111
and Gray code MSB will always Binary 11101101 Gray Code Digit 3 =1+1=0 (carry 1)
be the same 6 0110 0101
3. To get the binary next-to-MSB 7 0111 0100 Binary 11101101 Gray Code Digit 4 =1+0=1
(i.e. next digit to the right) add 8 1000 1100
the binary MSB and the gray Binary 11101101 Gray Code Digit 5 =0+1=1
code next-to-MSB. Record the 9 1001 1101
sum, ignoring any carry. 10 1010 1111 Binary 11101101 Gray Code Digit 6 =1+1=0 (carry 1)
4. Continue in this manner right 11 1011 1110
through to the end. 12 1100 1010 Binary 11101101 Gray Code Digit 7 =1+0=1
13 1101 1011 Binary 11101101 Gray Code Digit 8 =0+1=1
14 1110 1001
15 1111 1000
11101101bin = 10011011gray

39 40

Gray to Decimal Conversion Gray Code (Continued)


• Question: Convert the Gray coded number 10011011 to its
binary equivalent. • Does this special Gray code property have
• Answer:
any value?
Gray Code 10011011 Binary Digit 1 = 1 (same as Gray code)
Gray Code 10011011 Binary Digit 2 =0+1=1 • An Example: Optical Shaft Encoder
Gray Code 10011011 Binary Digit 3 =0+1=1 111 000 100 000
B0
Gray Code 10011011 Binary Digit 4 =1+1=0 (carry 1)
B1
110 001 101 001
Gray Code 10011011 Binary Digit 5 =1+0=1 B2

Gray Code 10011011 Binary Digit 6 =0+1=1 G2


G1
Gray Code 10011011 Binary Digit 7 =1+1=0 (carry 1) 111 G0
101 010 011
Gray Code 10011011 Binary Digit 8 =1+0=1

100 011 110 010


10011011gray = 11101101bin
(a) Binary Code for Positions 0 through 7 (b) Gray Code for Positions 0 through 7
41 42

Copyright 2000 N. AYDIN. All rights


reserved. 7
Gray Code (Continued) Gray Code (Continued)
• How does the shaft encoder work? • For the Gray code, what codes may be
produced if the shaft position lies between
codes for 3 and 4 (010 and 110)?
• For the binary code, what codes may be
produced if the shaft position lies between • Is this a problem?
codes for 3 and 4 (011 and 100)?
• Does the Gray code function correctly for
• Is this a problem? these borderline shaft positions for all cases
encountered in octal counting?

43 44

4221 BCD Code Warning: Conversion or Coding?


1's
• The 4221 BCD code is another Decimal 4221
binary coded decimal code where
complement • Do NOT mix up conversion of a decimal
each bit is weighted by 4, 2, 2 and 0 0000 1111 number to a binary number with coding a
1 respectively. Unlike BCD
1 0001 1110
coding there are no invalid decimal number with a BINARY CODE.
representations. 2 0010 1101
• The 1's complement of a 4221
representation is important in 3 0011 1100 • 1310 = 11012 (This is conversion)
decimal arithmetic. In forming the
code remember the following
rules
4
5
1000
0111
0111
1000
• 13 ⇔ 0001|0011 (This is coding)
• Below decimal 5 use the right-
6 1100 0011
most bit representing 2 first
• Above decimal 5 use the left-most 7 1101 0010
bit representing 2 first
8 1110 0001
• Decimal 5 = 2+2+1 and not 4+1
9 1111 0000

45 46

Binary Arithmetic Single Bit Binary Addition with Carry

• Single Bit Addition with Carry Given two binary digits (X,Y), a carry in (Z) we get the
following sum (S) and carry (C):
• Multiple Bit Addition
Carry in (Z) of 0: Z 0 0 0 0
• Single Bit Subtraction with Borrow X 0 0 1 1
• Multiple Bit Subtraction +Y +0 +1 +0 +1
CS 00 01 01 10
• Multiplication
Carry in (Z) of 1: Z 1 1 1 1
• BCD Addition X 0 0 1 1
+Y +0 +1 +0 +1
CS 01 10 10 11

47 48

Copyright 2000 N. AYDIN. All rights


reserved. 8
Multiple Bit Binary Addition Single Bit Binary Subtraction with Borrow

• Extending this to two multiple bit • Given two binary digits (X,Y), a borrow in (Z) we
examples: get the following difference (S) and borrow (B):
• Borrow in (Z) of 0: Z 0 0 0 0
Carries 00000 10110 0
X 0 0 1 1
Augend 01100 10110 -Y -0 -1 -0 -1
Addend +10001 +10111 BS 00 11 01 00
• Borrow in (Z) of 1: Z 1 1 1 1
Sum 11101 101101
• Note: The 0 is the default Carry-In to the X 0 0 1 1
least significant bit. -Y -0 -1 -0 -1
BS 11 10 00 11
49 50

Multiple Bit Binary Subtraction Binary Multiplication

• Extending this to two multiple bit examples: The binary multiplication table is simple:
Borrows 00000 0011 0 0 ∗0 = 0 | 1 ∗0 = 0 | 0 ∗1 = 0 | 1 ∗1 = 1
Minuend 10110 10110 Extending multiplication to multiple digits:
Subtrahend - 10010 - 10011 Multiplicand 1011
Difference 00100 00011 Multiplier x 101
Partial Products 1011
• Notes: The 0 is a Borrow-In to the least significant
0000 -
bit. If the Subtrahend > the Minuend, interchange
and append a – to the result. 1011 - -
Product 110111
51 52

BCD Arithmetic BCD Addition Example


 Given a BCD code, we use binary arithmetic to add the digits: • Addition is analogous to decimal addition with
8 1000 Eight
normal binary addition taking place from right to
+5 +0101 Plus 5
13 1101 is 13 (> 9) left. For example,
 Note that the result is MORE THAN 9, so must be
represented by two digits!
6 0110 BCD for 6 42 0100 0010 BCD for 42
 To correct the digit, subtract 10 by adding 6 modulo 16. +3 0011 BCD for 3 +27 0010 0111 BCD for 27
8 1000 Eight
+5 +0101 Plus 5 _______ ____________
13 1101 is 13 (> 9) 1001 BCD for 9 0110 1001 BCD for 69
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer (two digits)
 If the digit sum is > 9, add one to the next significant digit
53 54

Copyright 2000 N. AYDIN. All rights


reserved. 9
BCD Addition Example-2 Error-Detection Codes
• Add 2905BCD to 1897BCD showing • Redundancy (e.g. extra information), in the form
of extra bits, can be incorporated into binary code
carries and digit corrections. words to detect and correct errors.
0111 0011 0011 1110 • A simple form of redundancy is parity, an extra bit
0001 1000 1001 0111 appended onto the code word to make the number
of 1’s odd or even. Parity can detect all single-bit
+ 0010 1001 0000 0101 errors and some multiple-bit errors.
• A code word has even parity if the number of 1’s
0100 10010 1010 1100 in the code word is even.
0000 0110 0110 0110 • A code word has odd parity if the number of 1’s in
0100 1000 10000 10010 the code word is odd.
4 8 0 2
55 56

4-Bit Parity Code Example ASCII Character Codes


• Fill in the even and odd parity bits: • American Standard Code for Information
Even Parity Odd Parity Interchange (Refer to Table 1-4 in the text)
Message - Parity Message - Parity • This code is a popular code used to represent
000 - 000 - information sent as character-based data. It uses
001 - 001 - 7-bits to represent:
010 - 010 - – 94 Graphic printing characters.
011 - 011 - – 34 Non-printing characters
100 - 100 - • Some non-printing characters are used for text
101 - 101 - format (e.g. BS = Backspace, CR = carriage
110 - 110 - return)
111 - 111 - • Other non-printing characters are used for record
• The codeword "1111" has even parity and the marking and flow control (e.g. STX and ETX start
codeword "1110" has odd parity. Both can be and end text areas).
used to represent 3-bit data.
57 58

ASCII Properties UNICODE

ASCII has some interesting properties: • UNICODE extends ASCII to 65,536


 Digits 0 to 9 span Hexadecimal values 3016 to 3916 . universal characters codes
 Upper case A-Z span 4116 to 5A16 .
 Lower case a -z span 6116 to 7A16 . – For encoding characters in world languages
• Lower to upper case translation (and vice versa)
occurs by flipping bit 6. – Available in many modern applications
 Delete (DEL) is all bits set, a carryover from when – 2 byte (16-bit) code words
punched paper tape was used to store messages.
 Punching all holes in a row erased a mistake! – See Reading Supplement – Unicode on the
Companion Website
http://www.prenhall.com/mano

59 60

Copyright 2000 N. AYDIN. All rights


reserved. 10
Data types Decimal Numbers
• Our first requirement is to find a way to represent information • “decimal” means that we have ten digits to use in our
(data) in a form that is mutually comprehensible by human and
representation (the symbols 0 through 9)
machine.
– Ultimately, we will have to develop schemes for • What is 3546?
representing all conceivable types of information - – it is three thousands plus five hundreds plus four tens plus
language, images, actions, etc.
six ones.
– We will start by examining different ways of representing
integers, and look for a form that suits the computer. – i.e. 3546 = 3.103 + 5.102 + 4.101 + 6.100
– Specifically, the devices that make up a computer are • How about negative numbers?
switches that can be on or off, i.e. at high or low voltage.
Thus they naturally provide us with two symbols to work – we use two more symbols to distinguish positive and
with: we can call them on & off, or (more usefully) 0 and 1. negative:

+ and -
61 62

Unsigned Binary Integers Signed Magnitude


• Leading bit is the sign bit -4 10100
Y = “abc” = a.22 + b.21 + c.20
-3 10011
(where the digits a, b, c can each take on the values of 0 or 1 only)
Y = “abc” = (-1)a (b.21 + c.20) -2 10010
N = number of bits 3-bits 5-bits 8-bits -1 10001
Range is: 0 000 00000 00000000 Range is: -0 10000
0 ≤ i < 2N - 1 -2N-1 + 1 < i < 2N-1 - 1
1 001 00001 00000001 +0 00000

2 010 00010 00000010 Problems: +1 00001


Problem: +2 00010
3 011 00011 00000011 • How do we do addition/subtraction?
• How do we represent
• We have two numbers for zero (+/-)! +3 00011
negative numbers? 4 100 00100 00000100
+4 00100
63 64

One’s Complement Two’s Complement


-4 11011 -16 10000
• Invert all bits • Transformation … …
-3 11100
– To transform a into -a, invert all -3 11101
-2 11101
If msb (most significant bit) is 1 then the bits in a and add 1 to the result
-2 11110
number is negative (same as signed -1 11110
magnitude) -1 11111
-0 11111 Range is:
0 00000
+0 00000 -2N-1 < i < 2N-1 - 1
Range is: +1 00001
-2N-1 + 1 < i < 2N-1 - 1 +1 00001 Advantages:
+2 00010
+2 00010 • Operations need not check the sign
+3 00011
Problems: • Only one representation for zero
+3 00011 … …
•Same as for signed magnitude
+4 00100 • Efficient use of all the bits
+15 01111
65 66

Copyright 2000 N. AYDIN. All rights


reserved. 11
Limitations of integer representations Real numbers
• Most numbers are not integer! • Our decimal system handles non-integer real numbers
– Even with integers, there are two other considerations: by adding yet another symbol - the decimal point (.) to
• Range: make a fixed point notation:
– The magnitude of the numbers we can represent is – e.g. 3456.78 = 3.103 + 4.102 + 5.101 + 6.100 + 7.10-1 + 8.10-2
determined by how many bits we use:
• e.g. with 32 bits the largest number we can represent is about +/- 2
billion, far too small for many purposes. • The floating point, or scientific, notation allows us to
represent very large and very small numbers (integer or
• Precision:
– The exactness with which we can specify a number:
real), with as much or as little precision as needed:
• e.g. a 32 bit number gives us 31 bits of precision, or roughly 9 – Unit of electric charge e = 1.602 176 462 x 10-19 Coulomb
figure precision in decimal repesentation.
– Volume of universe = 1 x 1085 cm3
• We need another data type! • the two components of these numbers are called the mantissa and the
exponent

67 68

Real numbers in binary IEEE-754 fp numbers - 1


s biased exp. fraction
• We mimic the decimal floating point notation to create a 32 bits: 1 8 bits 23 bits
“hybrid” binary floating point number:
N= (-1)s x 1.fraction x 2(biased exp. – 127)
– We first use a “binary point” to separate whole numbers from
fractional numbers to make a fixed point notation:
• Sign: 1 bit
• e.g. 00011001.110 = 1.24 + 1.103 + 1.101 + 1.2-1 + 1.2-2 => 25.75 • Mantissa: 23 bits
(2-1 = 0.5 and 2-2 = 0.25, etc.)
– We “normalize” the mantissa by dropping the leading 1 and
recording only its fractional part (why?)
– We then “float” the binary point:
• 00011001.110 => 1.1001110 x 24
• Exponent: 8 bits
mantissa = 1.1001110, exponent = 4 – In order to handle both +ve and -ve exponents, we add 127
to the actual exponent to create a “biased exponent”:
– Now we have to express this without the extra symbols ( x, 2, . ) • 2-127 => biased exponent = 0000 0000 (= 0)
• 20 => biased exponent = 0111 1111 (= 127)
• by convention, we divide the available bits into three fields:
• 2+127 => biased exponent = 1111 1110 (= 254)
sign, mantissa, exponent
69 70

IEEE-754 fp numbers - 2 IEEE-754 fp numbers - 3


• Example: Find the corresponding fp representation of 25.75
• Double precision (64 bit) floating point
• 25.75 => 00011001.110 => 1.1001110 x 24
64 bits: 1 11 bits 52 bits
• sign bit = 0 (+ve)
• normalized mantissa (fraction) = 100 1110 0000 0000 0000 0000 s biased exp. fraction
• biased exponent = 4 + 127 = 131 => 1000 0011
• so 25.75 => 0 1000 0011 100 1110 0000 0000 0000 0000 => x41CE0000
N= (-1)s x 1.fraction x 2(biased exp. – 1023)
• Values represented by convention:
 Range & Precision:
– Infinity (+ and -): exponent = 255 (1111 1111) and fraction = 0  32 bit:
– NaN (not a number): exponent = 255 and fraction ≠ 0  mantissa of 23 bits + 1 => approx. 7 digits decimal
 2+/-127 => approx. 10+/-38
– Zero (0): exponent = 0 and fraction = 0
 64 bit:
• note: exponent = 0 => fraction is de-normalized, i.e no hidden 1  mantissa of 52 bits + 1 => approx. 15 digits decimal
 2+/-1023 => approx. 10+/-306

71 72

Copyright 2000 N. AYDIN. All rights


reserved. 12
Another use for bits: Logic Basic Logic Operations
TruthTables of Basic Operations
• Beyond numbers AND OR
NOT
– logical variables can be true or false, on or off, etc., and so A A' A B A.B A B A+B
are readily represented by the binary system. 0 0 0 0 0 0
0 1
– A logical variable A can take the values false = 0 or true = 1 1 0 0 1 0 0 1 1
only. 1 0 0 1 0 1
– The manipulation of logical variables is known as Boolean 1 1 1 1 1 1
Algebra, and has its own set of operations - which are not to • Equivalent Notations
be confused with the arithmetical operations.
– not A = A' = A
– Some basic operations: NOT, AND, OR, XOR – A and B = A.B = A∧B = A intersection B
– A or B = A+B = A∨B = A union B
73 74

More Logic Operations

XOR XNOR
A B A⊕B A B (A⊕B)'
0 0 0 0 0 1
0 1 1 0 1 0
1 0 1 1 0 0
1 1 0 1 1 1

– Exclusive OR (XOR): either A or B is 1, not both


– A⊕B = A.B' + A'.B

75

Copyright 2000 N. AYDIN. All rights


reserved. 13

You might also like