Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Digital Logic: Encoding and Adding Unsigned Numbers in Binary and Other Bases, Study notes of Electrical and Electronics Engineering

The encoding of larger values as binary numbers and the addition of unsigned numbers using binary representation. It includes examples of converting decimal numbers to binary using both the subtraction and division methods, as well as examples of binary addition with carry. The document also touches on the use of other number bases, such as octal and hexadecimal, and their conversion to and from binary.

Typology: Study notes

Pre 2010

Uploaded on 08/30/2009

koofers-user-ldw-3
koofers-user-ldw-3 🇺🇸

5

(1)

10 documents

1 / 12

Toggle sidebar

Related documents


Partial preview of the text

Download Digital Logic: Encoding and Adding Unsigned Numbers in Binary and Other Bases and more Study notes Electrical and Electronics Engineering in PDF only on Docsity! 1 ECE 274 - Digital Logic Lecture 11 Lecture 11 – Chapter 5 Positional Number Representation Addition of Unsigned Numbers 2 ECE 274 - Digital Logic Encoding Numbers Inputs to digital systems not limited to a single 1 or 0 Integer values, temperature, time, currency, images Previously, we said our digital system deal with 1s and 0s only How do we encode these larger values? Look at encoding numbers b a F = a + b 14 5 average(5, 14) 3 ECE 274 - Digital Logic Encoding Numbers: Decimal Numbers 104 103 102 5 2 3 101 100 Base ten (Decimal) Each position represents a quantity Symbol in position means how many of that quantity Ten symbols: 0, 1, 2, ..., 8, and 9 More than 9 -- next position So each position power of 10 Nothing special about base 10 -- used because we have 10 fingers 523 = (5 * 102) + (2 * 101) + (3 * 100) = (5 * 100) + (2 * 10) + (3 * 1) 4 ECE 274 - Digital Logic Encoding Numbers: Binary Numbers (Base 2) 24 23 22 1 0 1 21 20 Q: How much? Base two (Binary) Two symbols: 0 and 1 More than 1 -- next position So each position power of 2 1012 = (1 * 22) + (0 * 21) + (1 * 20) = (1 * 4) + (0 * 2) + (1 * 1) = 510 “one zero one” 101 “one hundred one” 1012 10110 = = 5 ECE 274 - Digital Logic Encoding Numbers: Binary Numbers Range of integer binary number can represent depends on bits used n bits can represent integers in the range of 0 to (2n – 1) Most-significant bit (MSB) Left-most bit Associated with highest power of 2 Least-significant bit (LSB) Right-most bit Associated with lowest power of 2 Convenient to group bits together 4 bits – nibble 8 bits - byte 112 = 310 11112 = 1510 1011 01112 = 18310 22 – 1 = 3 24 – 1 = 15 28 – 1 = 255 1011 0111 MSB LSB 1011 0111 1011 0111 nibble byte 6 ECE 274 - Digital Logic Decimal Equivalent of a Binary Number – Example 1 What is the decimal equivalent? 1102 = ? Decimal 22 21 20 1 1 0 1102 = (1 * 22) + (1 * 21) + (0 * 20) = (1 * 4) + (1 * 2) + (0 * 1) = 610 13 ECE 274 - Digital Logic Encoding Numbers: Octal Representation (Base 8) 000 001 010 011 100 101 110 111 0 1 2 3 4 5 6 7 octal binary Q: Write 111100002 in octal Other bases available Base 8 – Octal Base 16 – Hexadecimal (hex) Octal Symbols Range from 0 to 7 Useful shorthand for binary Binary to Octal conversion Group binary numbers in 3’s Replace with corresponding octal digit Octal to Binary conversion Replace octal digit with corresponding 3 bits denoting same value 63 0 8 Q: Write 7548 in binary 101111 100 2 Q: Write 278 in decimal (2 * 81) + (7 * 80) = 2310 84 83 82 4 6 1 81 80 Symbols = (0, 1, 2, 3, 4, 5, 6, 7) 14 ECE 274 - Digital Logic Encoding Numbers: Hexadecimal Numbers (Base 16) 0000 0001 0010 0011 0100 0101 0110 0111 0 1 2 3 4 5 6 7 hex binary 1000 1001 1010 1011 1100 1101 1110 1111 8 9 A B C D E F hex binary 164 163 162 8 A F 161 160 Symbols = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) Q: Write 1111 01002 in hex F 4 16 Q: Write 8AF8 in binary 10101000 1111 2 Q: Write AC16 in decimal (10 * 161) + (12 * 160) = 17210 Hex Each position represents four base two positions Used as compact means to write binary numbers Symbols range from 0 to F Binary to Hex conversion Group binary numbers in 4’s Replace with corresponding hex digit Hex to Binary conversion Replace hex digit with corresponding 4 bits denoting same value 15 ECE 274 - Digital Logic Number Representation for Computers vs. for Humans Modern computer represent numbers using 32 or 64 bits Binary representation can be confusing for humans Datasheet, documentation, etc. generally uses hex Introduced simple numbers Only positive values – unsigned numbers Later we’ll consider Signed numbers (positive & negative integers) Fixed-point Floating-point 2 00001111101000001000000111000011 0FA081C3 16 16 ECE 274 - Digital Logic Addition of Unsigned Numbers Common operation performed by computer – addition of unsigned numbers Add two 1-bit numbers What are the possible values? + 1 1 01 + 1 0 10 + 0 1 10 + 0 0 00 + x y sc sumcarry operand 1 operand 2 x y cs 0 0 00 0 1 01 1 0 01 1 1 10 based on this observation we can create a truth table 17 ECE 274 - Digital Logic Half-Adder Let’s create circuit to perform addition sum= x XOR y carry = xy Special type of circuit – half adder Adds two bits x y cs 0 0 00 0 1 01 1 0 01 1 1 10 s c x y Circuit yx HA sc Graphical Symbol 18 ECE 274 - Digital Logic Addition of Multi-Bit Unsigned Numbers What if we want to bigger numbers (i.e. multiple bit numbers)? Addition of two 2-bit numbers + C B1 S1 B0 S0 A1 A0 A1 = A1’A0’B1 + A1’B1B0’ + A0B1’B0 + A1A0B1’ + A1B1’B0 A0 = A1’A0’B1B0 + A1’A0B0’ + A1A0B0 + A1A0’B0’ C = A0B1B0 + A1A0B0 + A1B1 A1 A1’ A0’ B1 A1’ B1 B0’ A0 B1’ B0 A1 A0 B1’ A1 B1’ B0 create corresponding circuit for each output B0 CB1A0A1 S1 S0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 0 0 0 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 create truth table 19 ECE 274 - Digital Logic Exponential Growth of Two-Level Adders What if we want to bigger numbers (i.e. multiple bit numbers)? Addition of two 3-bit numbers Addition of two 4-bit numbers Addition of two n-bit numbers + C B2 S2 B1 S1 B0 S0 A2 A1 A0 truth table with 26 rows = 64 rows + C B3 S3 B2 S2 B1 S1 B0 S0 A3 A2 A1 A0 truth table with 28 rows = 256 rows 10000 8000 6000 4000 2000 0 1 2 3 4 5 N 6 7 8 Tr an si st or s Exponential Growth for Two-Level Adder Implementation 20 ECE 274 - Digital Logic Addition of Unsigned Numbers with Carry Instead we can consider each column separately + 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 need to consider possible carry bit from previous row + x y sci+1 sumcarry out operand 2 ci operand 1 carry in + 0 00 0 0 + 1 10 0 0 + 0 10 1 0 + 1 01 1 0 + 0 10 0 1 + 1 01 0 1 + 0 01 1 1 + 1 11 1 1 based on this observation we can create a truth table y ci+1s 0 00 1 01 0 01 1 10 0 01 1 10 0 10 1 11 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 xci 21 ECE 274 - Digital Logic Full Adder Let’s create circuit to perform addition sum= x XOR y XOR ci carry = xy + xci + yci Special type of circuit – full adder Adds three bits y ci+1s 0 00 1 01 0 01 1 10 0 01 1 10 0 10 1 11 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 xci s ci+1 x y Circuit ci Graphical Symbol x FA sci+1 y ci 28 ECE 274 - Digital Logic Design Example: Multiple by 3 Note 3I = I + I + I ci+1 ci s7 s6 s5 s4 B7 B6 B5 B4 8-bit adder A3 A2 A1 A0A7 A6 A5 A4 B3 B2 B1 B0 s3 s2 s1 s0 I3 I2 I1 I0I7 I6 I5 I4 I3 I2 I1 I0I7 I6 I5 I4 0 ci+1 ci s7 s6 s5 s4 B7 B6 B5 B4 9-bit adder A3 A2 A1 A0A7 A6 A5 A4 B3 B2 B1 B0 s3 s2 s1 s0 B8A8 s8 I3 I2 I1 I0I7 I6 I5 I4 0 0 P3 P2 P1 P0P7 P6 P5 P4P8P9 29 ECE 274 - Digital Logic Design Example: Multiply by 3 Using Shift Left Alternatively we should shift bits in I one position to left Shift Left Operation (<<) effectively multiplies value by 2 I << 2 = I * 2 00012 = 110 00102 = 210 01002 = 410 10002 = 810 00112 = 310 01102 = 610 11002 = 1210 ci+1 ci s7 s6 s5 s4 B7 B6 B5 B4 9-bit adder A3 A2 A1 A0A7 A6 A5 A4 B3 B2 B1 B0 s3 s2 s1 s0 B8A8 s8 I3 I2 I1 I0I7 I6 I5 I4 0 0 P3 P2 P1 P0P7 P6 P5 P4P8P9 0I3 I2 I1 I0I7 I6 I5 I4 2I + I 3I 30 ECE 274 - Digital Logic Shift Right, Same as Divide by 2 Shifting works other way too Shift bits in I one position to right Shift Right Operation (>>) effectively divides value by 2 I >> 2 = I / 2 00012 = 110 00102 = 210 01002 = 410 10002 = 810 00112 = 310 01102 = 610 11002 = 1210 31 ECE 274 - Digital Logic Design Example: Compensating Scale Design Example: Compensating Scale Over time scale accuracy deteriorates Design a circuit that will weigh an object, and add an adjustment from a user Input 8-bit weight Reported by Sensor 3-bit User Adjustment Output 8-bit sum of inputs 32 ECE 274 - Digital Logic Design Example: Compensating Scale ci+1 ci to display B3 B2 B1 B0 8-bit adder Weight Sensor Adjustment Knob 0 1 26 3 4 5 7 0 Weight Adjuster A3 A2 A1 A0A7 A6 A5 A4 B7 B6 B5 B4 00 0 0 0 s3 s2 s1 s0s7 s6 s5 s4 33 ECE 274 - Digital Logic Design Example: 8-bit Calculator Design Example: 8-bit Calculator Add two numbers controlled by DIP switches Output result using eight LEDs Input 8-bit input A 8-bit input B Output 8-bit sum S 34 ECE 274 - Digital Logic Design Example: 8-bit Calculator 8-bit DIP switch based adding calculator. The addition 2+3=5 is shown. ci+1 0 s7 s6 s5 s4 B7 B6 B5 B4 8-bit adder A3 A2 A1 A0A7 A6 A5 A4 B3 B2 B1 B0 s3 s2 s1 s0 LEDs DIP Switches Calculator ci
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved