100% found this document useful (1 vote)
51 views

Data Communication

This document discusses different number systems including binary, decimal, octal, and hexadecimal. It provides examples of converting between these number systems, as well as performing arithmetic operations like addition, subtraction, multiplication, and division in binary. Binary coded decimal and gray code are also mentioned. The key concepts covered are number-base conversion, binary arithmetic, and different methods for representing signed numbers like one's complement and two's complement.

Uploaded by

Johnny
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
51 views

Data Communication

This document discusses different number systems including binary, decimal, octal, and hexadecimal. It provides examples of converting between these number systems, as well as performing arithmetic operations like addition, subtraction, multiplication, and division in binary. Binary coded decimal and gray code are also mentioned. The key concepts covered are number-base conversion, binary arithmetic, and different methods for representing signed numbers like one's complement and two's complement.

Uploaded by

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

Lecture 2: Number Systems

Syed M. Mahmud, Ph.D


ECE Department
Wayne State University

Original Source: Prof. Russell Tessier of University of Massachusetts


Aby George of Wayne State University
Contents
• Number systems
• Binary arithmetic
• Number-base conversion
• Complement of numbers
• Binary Coded Decimal & Gray Code
• Logic operations

Chapter 1 ECE 2610 – Digital Logic 1 2


Number System
Decimal System
It has 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
It's also known as Base 10 or Radix 10 system

Integer
(273)10 = 200 + 70 +3 = 2*102 + 7*101 +3*100
Fraction
(0.526)10 = 0.5 + 0.02 + 0.006 = 5*10-1 + 2*10-2 +6*10-3

Chapter 1
Decimal System
(543.67)10 = 5*102 + 4*101 +3*100 + 6*10-1 +7*10-2

(2083.4705)10
= 2*103 + 0*102 + 8*101 +3*100 + 4*10-1 +7*10-2 + 0*10-3 +5*10-4
Why do we use 10 digits, anyway?

Chapter 1
Binary System
It has 2 digits: 0 and 1
It's also known as Base 2 or Radix 2 system
A computer does all of its calcualtions using Binary System
A 0 is analogous to a Switch is OFF
A 1 is analogous to a Switch is ON
A Binary Digits is call a BIT (Binary digIT)
A group of 8 Bits is called a Byte
Examples: 11010010, 10110001, 10001101, etc.
A group of 4 Bits is called a Nibble
Examples: 1101, 0010, 1011, 0001, 1000, 1101, etc.
Chapter 1 5
Why Use Binary Numbers?
° Easy to represent 0 and 1 using
electrical values.
° Possible to tolerate noise.
° Easy to transmit data
° Easy to build binary circuits.

AND Gate

1
0
0
Binary System
Conversion from Binary to Decimal
(101.11)2 = 1*22 + 0*21 +1*20 + 1*2-1 +1*2-2
= 4 + 0 + 1 + 1/2 + 1/4
= 4 + 0 + 1 + 0.5 + 0.25
= (5.75)10

Chapter 1 7
Octal System
It has 8 digits: 0, 1, 2, 3, 4, 5, 6, 7
It's also known as Base 8 or Radix 8 system

Conversion from Octal to Decimal


(431.65)8 = 4*82 + 3*81 +1*80 + 6*8-1 +5*8-2
= 4*64 + 3*8 + 1 + 6/8 + 5/64
= (281.828125)10

Chapter 1 8
Hexadecimal System
It has 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
It's also known as Base 16 or Radix 16 system

Conversion from Hexadecimal to Decimal


(A2B.DB)16 = 10*162 + 2*161 +11*160 + 13*16-1 +11*16-2
= 10*256 + 2*16 + 11 + 13/16 + 11/256
= (2603.85546875)10

Chapter 1 9
Example: Any radix to Decimal Conversion

Chapter 1 ECE 2610 – Digital Logic 1 10


Conversion Between Number Bases
Octal(base 8)

Decimal(base 10) Binary(base 2)

Hexadecimal
(base16)
° Learn to convert between bases.
° Already demonstrated how to convert
from binary to decimal.
Convert an Integer from Decimal to Another Base
For each digit position:
1. Divide decimal number by the base (e.g. 2)
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor remains.

Example for (13)10:


Integer Remainder Coefficient
Quotient
13/2 = 6 + 1 a0 = 1
6/2 = 3 + 0 a1 = 0
3/2 = 1 + 1 a2 = 1
1/2 = 0 + 1 a3 = 1

Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2


Convert a Fraction from Decimal to Another Base
For each digit position:
1. Multiply decimal number by the base (e.g. 2)
2. The integer is the highest-order digit
3. Repeat first two steps until fraction becomes
zero.
Example for (0.625)10:
Integer Fraction Coefficient

0.625 x 2 = 1 + 0.25 a-1 = 1


0.250 x 2 = 0 + 0.50 a-2 = 0
0.500 x 2 = 1 + 0 a-3 = 1

Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2


Powers of Two

Chapter 1 ECE 2610 – Digital Logic 1 14


Numbers with Different Bases

Chapter 1 ECE 2610 – Digital Logic 1


Binary Addition
• Binary addition is very simple.
• This is best shown in an example of adding two
binary numbers…

1 1 1 1 1 1 carries
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
1 0 1 0 1 0 0
Binary Subtraction
° We can also perform subtraction (with borrows in place of
carries).
° Let’s subtract (10111)2 from (1001101)2…

1 10 borrows
0 10 10 0 0 10

1 0
0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0
Binary Multiplication
• Binary multiplication is much the same as decimal
multiplication, except that the multiplication
operations are much simpler…
10 1 1 1
X 1 0 1 0
-----------------------
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
-----------------------
1 1 1 0 0 1 1 0
Binary Division
25/5 1 0 1

1 0 1 1 1 0 0 1

1 0 1

0 0 1 0

0 0 0

1 0 1

1 0 1

0 0 0

Chapter 1 ECE 2610 – Digital Logic 1 19


Convert an Integer from Decimal to Octal
For each digit position:
1. Divide decimal number by the base (8)
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor remains.

Example for (175)10:


Integer Remainder Coefficient
Quotient
175/8 = 21 + 7 a0 = 7
21/8 = 2 + 5 a1 = 5
2/8 = 0 + 2 a2 = 2

Answer (175)10 = (a2 a1 a0)2 = (257)8


Convert a Fraction from Decimal to Octal
For each digit position:
1. Multiply decimal number by the base (e.g. 8)
2. The integer is the highest-order digit
3. Repeat first two steps until fraction becomes
zero.
Example for (0.3125)10:
Integer Fraction Coefficient

0.3125 x 8 = 2 + 0.5 a-1 = 2


0.5000 x 8 = 4 + 0.0 a-2 = 4

Answer (0.3125)10 = (0.24)8


Number – Base Conversion - More Examples

2 13 5 13 8 13

2 6 --1 2 --3 1 --5

2 3 --0

1 --1

Chapter 1 ECE 2610 – Digital Logic 1 22


Number – Base Conversion - More Examples

.75
.5 x2
x2 1 .5
1 .0 x2
1 .0

Chapter 1 ECE 2610 – Digital Logic 1 23


Number – Base Conversion - More Examples

.513
x8
4 .104
x8
0 .832
x8
6 .656
x8
5 .248

Chapter 1 ECE 2610 – Digital Logic 1 24


Octal and Hexadecimal Numbers

(10 110 001 101 011 . 111 100)2

(2 6 1 5 3 . 7 4)8

(10 1100 0110 1011 . 1111 00)2


(2 C 6 B . F 0)8

Chapter 1 ECE 2610 – Digital Logic 1 25


Octal and Hexadecimal Numbers
• Octal to Binary
(6 7 3 . 1 2)8
(110 111 011 . 001 010)2

• Binary to Hexadecimal
(3 0 6 . D)16
(0011 0000 0110 . 1101)2

Chapter 1 ECE 2610 – Digital Logic 1 26


How To Represent Signed Numbers

Consider signed magnitude:

000011002 = 1210 100011002 = -1210

Sign bit Magnitude Sign bit Magnitude


One’s Complement Representation
• The one’s complement of a binary number
involves inverting all bits.
• 1’s comp of 00110011 is 11001100
• 1’s comp of 10101010 is 01010101
• For an n bit number N the 1’s complement is
(2n-1) – N.
• Called diminished radix complement by Mano
since 1’s complement for base (radix 2).
• To find negative of 1’s complement number
take the 1’s complement.
000011002 = 1210 111100112 = -1210

Sign bit Magnitude Sign bit Magnitude


Two’s Complement Representation
• The two’s complement of a binary number involves
inverting all bits and adding 1.
• 2’s comp of 00110011 is 11001101
• 2’s comp of 10101010 is 01010110
• For an n bit number N the 2’s complement is 2n – N.
• Called radix complement by Mano since 2’s
complement for base (radix 2).
• To find negative of 2’s complement number take the 2’s
complement.

000011002 = 1210 111101002 = -1210

Sign bit Magnitude Sign bit Magnitude


Two’s Complement Shortcuts
• Algorithm 1 – Simply complement each bit and
then add 1 to the result.
• Finding the 2’s complement of (01100101)2 and of its
2’s complement…
N = 01100101 [N] = 10011011
10011010 01100100
+ 1 + 1
--------------- ---------------
10011011 01100101
• Algorithm 2 – Starting with the least significant bit,
copy all of the bits up to and including the first 1
bit and then complementing the remaining bits.
• N =01100101
[N] =10011011
Finite Number Representation
• Machines that use 2’s complement arithmetic can
represent integers in the range
-2n-1 <= N <= 2n-1-1
where n is the number of bits available for
representing N. Note that 2n-1-1 = (011..11)2
and –2n-1 = (100..00)2
• For 2’s complement more negative numbers than
positive.
• For 1’s complement two representations for zero.
• For an n bit number in base (radix) z there are zn
different unsigned values.
(0, 1, …zn-1)
1’s Complement Addition
• Using 1’s complement numbers, adding numbers is easy.
• For example, suppose we wish to add +(00001100)2 and
+(00000001)2.
• Let’s compute (12)10 + (1)10.
• (12)10 = +(00001100)2 = 000011002 in 1’s comp.
• (1)10 = +(00000001)2 = 000000012 in 1’s comp. 0 0 0 0 1 1 0 0
Add + 0 0 0 0 0 0 0 1
Step 1: Add binary numbers ---------------
Step 2: Add carry to low-order bit 0 0 0 0 0 1 1 0 1
Add carry 0
---------------
Final Result 0 0 0 0 1 1 0 1
1’s Complement Subtraction
• Using 1’s complement numbers, subtracting numbers
is also easy.
• For example, suppose we wish to subtract 0 0 0 0 1 1 0 0
+(00000001)2 from +(00001100)2. - 0 0 0 0 0 0 0 1
---------------
• Let’s compute (12)10 - (1)10.
• (12)10 = +(00001100)2 = 000011002 in 1’s comp. 1’s
• -(1)10 = -(00000001)2 = 111111102 in 1’s comp. comp
0 0 0 0 1 1 0 0
Add + 1 1 1 1 1 1 1 0
Step 1: Take 1’s complement of 2 operand
nd
---------------
Step 2: Add binary numbers
1 0 0 0 0 1 0 1 0
Step 3: Add carry to low order bit Add carry 1
---------------
Final Result 0 0 0 0 1 0 1 1
2’s Complement Addition
• Using 2’s complement numbers, adding numbers is easy.
• For example, suppose we wish to add +(00001100)2 and
+(00000001)2.
• Let’s compute (12)10 + (1)10.
• (12)10 = +(00001100)2 = 000011002 in 2’s comp.
• (1)10 = +(00000001)2 = 000000012 in 2’s comp. 0 0 0 0 1 1 0 0
Add + 0 0 0 0 0 0 0 1
Step 1: Add binary numbers ---------------
Step 2: Ignore carry bit Final Result 0 0 0 0 0 1 1 0 1

Ignore
2’s Complement Subtraction
• Using 2’s complement numbers, follow steps for
subtraction
• For example, suppose we wish to subtract +(00000001)2
from +(00001100)2. 0 0 0 0 1 1 0 0
- 0 0 0 0 0 0 0 1
• Let’s compute (12)10 - (1)10.
---------------
• (12)10 = +(00001100)2 = 000011002 in 2’s comp. 2’s
• -(1)10 = -(00000001)2 = 111111112 in 2’s comp. comp
0 0 0 0 1 1 0 0
Add + 1 1 1 1 1 1 1 1
Step 1: Take 2’s complement of 2nd operand ---------------
Step 2: Add binary numbers Final
Result 1 0 0 0 0 1 0 1 1
Step 3: Ignore carry bit
Ignore
Carry
2’s Complement Subtraction: Example #2
• Let’s compute (13)10 – (5)10.
• (13)10 = +(00001101)2 = 000011012 in 2's comp
• -(5)10 = -(00000101)2 = 111110112 in 2's comp
• Adding these two 8-bit codes…
0 0 0 0 1 1 0 1
+ 1 1 1 1 1 0 1 1
---------------
ignore carry
1 0 0 0 0 1 0 0 0

• Discarding the carry bit, the sign bit is seen to be


zero, indicating a correct result. Indeed,
(00001000)2 = +(8)10.
2’s Complement Subtraction: Example #3
• Let’s compute (5)10 – (12)10.
• (5)10 = +(00000101)2 = 000001012 in 2’s comp.
• -(12)10 = -(00001100)2 = 111101002 in 2’s comp.

• Adding these two 8-bit codes…


0 0 0 0 0 1 0 1
+ 1 1 1 1 0 1 0 0
---------------
1 1 1 1 1 0 0 1
• Here, there is no carry bit and the sign bit is 1.
This indicates a negative result, which is what we
expect. (11111001)2 = -(00000111) = -(7)10.
Signed binary numbers
• Leftmost bit of the signed binary number represents the sign.
• 0 -> Positive
• 1 -> Negative

Chapter 1 ECE 2610 – Digital Logic 1 38


Binary Coded Decimal Code (BCD)

Chapter 1 ECE 2610 – Digital Logic 1 39


Gray Code
• The advantage of the Gray code over the straight binary number
sequence is that only one bit in the code group changes in going from
one number to the next.

1 0 1 0

1 1 1 1

1 1 1 1

1 0 1 0

Chapter 1 ECE 2610 – Digital Logic 1 40


ASCII Code
• American Standard Code for Information Interchange
• ASCII is a 7-bit code, frequently used with an 8th bit
for error detection (more about that in a bit).
Character ASCII (bin) ASCII (hex) Decimal Octal
A 1000001 41 65 101
B 1000010 42 66 102
C 1000011 43 67 103

Z
a

1

ASCII Codes and Data Transmission

° ASCII Codes
° A – Z (26 codes), a – z (26 codes)
° 0-9 (10 codes), others (@#$%^&*….)
° Complete listing in Mano text
° Transmission susceptible to noise
° Typical transmission rates (1500 Kbps, 56.6 Kbps)
° How to keep data transmission accurate?
Parity Codes
• Parity codes are formed by concatenating a parity
bit, P to each code word of C.
• In an odd-parity code, the parity bit is specified so
that the total number of ones is odd.
• In an even-parity code, the parity bit is specified so
that the total number of ones is even.

P Information Bits

1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1
 
Added even parity bit Added odd parity bit
Parity Code Example
• Concatenate a parity bit to the ASCII code for the
characters 0, X, and = to produce both odd-parity
and even-parity codes.
Character ASCII Odd-Parity Even-Parity
ASCII ASCII

0 0110000 10110000 00110000

X 1011000 01011000 11011000

= 0111100 10111100 00111100


Other Codes
• 2421 decimal code
• Excess-3 decimal code
• 8,4,-2,-1 decimal code
• American Standard Code for Information Interchange (ASCII)
character code
• Error detecting codes – odd parity, even parity
• Read section 1.7

Chapter 1 ECE 2610 – Digital Logic 1 45


Binary Data Storage
• Binary cells store individual bits of data
• Multiple cells form a register.
• Data in registers can indicate different values
• Hex (decimal)
• BCD
• ASCII

0 0 1 0 1 0 1 1

Binary Cell
Register Transfer
• Data can move from register to register.
• Digital logic used to process data
• We will learn to design this logic

Register A Register B

Digital Logic
Circuits

Register C
Transfer of Information
• Data input at keyboard
• Shifted into place
• Stored in memory

NOTE: Data input in ASCII


Building a Computer
• We need processing
• We need storage
• We need communication

• You will learn to use and


design these components.
Binary logic - NOT operation
Student
took Student
2610 did not
take
2610

Student
in ECE

Chapter 1 ECE 2610 – Digital Logic 1 50


Binary logic - AND operation

Student
Student took 2610 Student
took AND 3300 took
2610 3300

Student
in ECE

Chapter 1 ECE 2610 – Digital Logic 1 51


Binary logic - OR operation

Student
Student took 2610 Student
took OR 3300 took
2610 3300

Student
in ECE

Chapter 1 ECE 2610 – Digital Logic 1 52


Logic symbols and truth table

Chapter 1 ECE 2610 – Digital Logic 1 53


Input output signals for gates

Chapter 1 ECE 2610 – Digital Logic 1 54


Summary
• How to convert between binary, octal, decimal, and hexadecimal
numbers?
• How to do the binary arithmetic operations?
• How to find the 1’s complement of a binary number?
• How to find the 2’s complement of a binary number?
• How to do the subtraction operation using 2’s complement method?
• What are the basic binary logic operations?

Chapter 1 ECE 2610 – Digital Logic 1 55


Homework 1 (Chapter 1)
• Number system
• 1.4, 1.8, 1.13
• Add, subtract, and multiply in binary:
(a) 1111 and 1010 (b) 110110 and 11101 (c) 100100 and 10110
• Binary arithmetic
• 1.14, 1.18
• Binary codes
• Convert the following decimal numbers to binary number, Gray code and BCD
a) (25)10 b) (58)10
• Convert the following Gray code numbers to binary numbers
a) 1110001 b) 101011

Chapter 1 ECE 2610 – Digital Logic 1 56

You might also like