ECE 421-Week 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

1.

Number Systems: decimal and binary


numbers, 1’s and 2’s complements
2. Hexadecimal and Octal numbers
3. Binary coded decimal (BCD) and digital
codes.
Number System

➢ Features of number systems:


▪ the number of independent digits used in the
number system (radix or base)
▪ the place values of the different digits
constituting the number (weight).
▪ the maximum numbers that can be written with
the given number of digits.
Binary Number System

➢ This system is known as binary number system as


its radix is two
➢ The digits 0 & 1 of this system are known as bits.
➢ With n bits you can count up to a number equal to
2n - 1
Binary Number System
Binary Arithmetic

Addition
➢ The four basic rules for adding binary digits (bits) are as
follows:
0+0=0 Sum of 0 with a carry of 0
0+1=1 Sum of 1 with a carry of 0
1+0=1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1
Subtraction
➢ The four basic rules for subtracting bits are as follows:
0-0=0
1-1=0
1-0=1
10 - 1 = 1 0 - 1 with a borrow of 1
Binary Arithmetic

Multiplication
➢ The four basic rules for multiplying bits are as follows:
0*0=0
0*1=0
1*0=0
1*1=1

Division
➢ Division in binary follows the same procedure as
division in decimal
Conversions between Binary and Decimal

Decimal to Binary conversion


➢Sum of Weights method: determine the set of
binary weights whose sum is equal to the decimal
number.
➢Repeated division-by-2 method
➢Repeated multiplication-by-2 method for fraction
Binary to Decimal conversion
➢ Add the weights of all bits that are 1 and discard
the weights of all bits that are 0.
1’s and 2’s Complements

➢The 1’s complement and the 2’s complement of a


binary number are important because they permit
the representation of negative numbers.
➢ 1’s complement of a binary number is found when
each 1 is replaced by 0 and each 0 is replaced by 1.
➢The 2’s complement of a binary number is found
by adding 1 to the LSB of the 1’s complement.
Sign-magnitude representation

➢A signed binary number consists of both sign and


magnitude information.
➢There are three forms in which signed integer
(whole) numbers can be represented in binary:
sign-magnitude, 1’s complement, and 2’s
complement.
➢When a signed binary number is represented in
sign-magnitude, the left-most bit is the sign bit and
the remaining bits are the magnitude bits.
➢A 0 sign bit indicates a positive number, and a 1
sign bit indicates a negative number.
Signed Forms of Binary numbers
Sign-Magnitude:
Change the sign bit to corresponding value e.g. +25 and -
25.
1’s Complement:
Positive numbers are represented the same way as the
positive sign-magnitude numbers. Negative numbers, are
the 1’s complements of the corresponding positive
numbers.
2’s Complement:
Positive numbers are represented the same way as in the
sign magnitude and 1’s complement forms. Negative
numbers are the 2’s complements of the corresponding
positive numbers.
The Decimal Value of Signed Numbers
Sign-Magnitude:
Sum the weights in all the magnitude bit positions
where there are 1s and ignoring those positions
where there are 0s.
1’s Complement:
Assign a negative value to the weight of the sign
bit, summing all the weights where there are 1s,
and adding 1 to the result.
2’s Complement:
The weight of the sign bit in a negative number is
given a negative value.
Arithmetic Operations with Signed Numbers
Addition
➢ Two positive signed numbers: the sum is positive and is
therefore in true (uncomplemented) binary
➢ Positive number with magnitude larger than negative
number: the final carry bit is discarded. The sum is
positive and therefore in true (uncomplemented) binary
➢ Negative number with magnitude larger than a positive
number: sum is negative and in 2’s complement.
➢ Both negative numbers: the final carry bit is discarded.
The sum is negative and therefore in 2’s complement form.
Subtraction
➢ To subtract two signed numbers, take the 2’s complement
of the subtrahend and add. Discard any final carry bit.
Arithmetic Operations with Signed Numbers

Multiplication
➢ Direct addition: add the multiplicand a number of times
equal to the multiplier.
➢ Partial products
Step 1: Determine if the signs of the multiplicand and
multiplier are the same or different.
➢ Step 2: take the 2’s complement of the multiplier
➢ Step 3: Starting with the least significant multiplier bit,
generate the partial products.
Step 4: Add each successive partial product to the sum
of the previous partial products to get the final product.
Step 5: If the sign bit that was determined in step 1 is
negative, take the 2’s complement of the product. If
positive, leave the product in its true form.
Arithmetic Operations with Signed Numbers

Division
➢ Step 1:Determine if the signs of the dividend and
divisor are the same or different. The quotient is initially
zero.
➢ Step 2: Subtract the divisor from the dividend using 2’s
complement addition. If this partial remainder is
positive, go to step 3. If the partial remainder is zero or
negative, the division is complete.
➢ Step 3: Subtract the divisor from the partial remainder
and add 1 to the quotient. If the result is positive, repeat
for the next partial remainder. If the result is zero or
negative, the division is complete.
Hexadecimal Number System

➢The radix or base is 16 and its digits will be 16


distinct elements which are given as: 0, 1, 2, 3, 4, 5,
6,7, 8, 9, A, B, C, D, E, F.
➢The hexadecimal number system provides a
condensed way of representing large binary
numbers stored and processed inside the
computer
Conversions: Decimal, Binary and Hexadecimal

Binary to Hexadecimal
➢Break the binary number into 4-bit groups,
starting at the right-most bit, and replace each 4-
bit group with the equivalent hexadecimal
symbol.
Hexadecimal to Binary
➢Replace each hexadecimal symbol with the
appropriate four bits
Conversions: Decimal, Binary and Hexadecimal

Hexadecimal to Decimal
➢ Convert the hexadecimal number to binary and
then convert from binary to decimal.
➢Multiply each hexadecimal digit by its weight and
then take the sum of these products.
Decimal to Hexadecimal
➢Repeated division of a decimal number by 16.
Octal Number System

➢ The octal number system is composed of eight


digits, which are 0, 1, 2, 3, 4, 5, 6, 7
➢ To count above 7, begin another column and start
over
Conversions: Decimal, Binary and Octal
Octal to Decimal
➢ Multiplying each digit by its weight and sum the
products
Decimal to Octal
➢Repeated division of a decimal number by 8.
Octal to Binary
➢ Replace each octal symbol with the appropriate three
bits
Binary to Octal
➢Convert each 3-bit group to the equivalent octal digit.
➢If there are not three bits for the left-most group, add
either one or two zeros to make a group.
Binary coded decimal (BCD)

➢The binary coded decimal (BCD) is a type of


binary code used to represent a given decimal
number in an equivalent binary form.
➢BCD-to-decimal and decimal-to-BCD conversions
are very easy and straightforward.
➢It is known as the 8421 BCD code, with 8, 4, 2 and
1 (23, 22, 21, 20)
➢Only the first 10 decimal numbers are represented
in BCD.
Binary coded decimal (BCD)
Decimal to BCD
The BCD equivalent of a decimal number is written
by replacing each decimal digit in the integer and
fractional parts with its four-bit binary equivalent.
BCD to Decimal
Start at the right-most bit and break the code into
groups of four bits.
Binary coded decimal (BCD)
Decimal to BCD
The BCD equivalent of a decimal number is written
by replacing each decimal digit in the integer and
fractional parts with its four-bit binary equivalent.
BCD to Decimal
Start at the right-most bit and break the code into
groups of four bits.
Digital Codes

➢ Digital codes are sequences of symbols used to


represent information in digital form.
➢ They include the gray code, alphanumeric codes
(ASCII), and the Unicode
➢ Gray code: It is an unweighted binary code in
which two successive values differ only by 1 bit.
Digital Codes

Binary-to-Gray Code Conversion


➢ The MSB in binary is the same as in the binary code
➢ From left to right, add each adjacent pair of binary
code bits to get the next Gray code bit. Discard
carries.
Gray-to-Binary Code Conversion
➢ The MSB in binary is the same as in the Gray code.
➢ Add each binary code bit generated to the Gray code
bit in the next adjacent position. Discard carries.
Digital Codes
➢Alphanumeric codes, also called character codes,
are binary codes used to represent alphanumeric
data.
➢The codes write alphanumeric data, including
letters of the alphabet, numbers, mathematical
symbols and punctuation marks, in a form that is
understandable and processable by a computer.
➢These codes enable us to interface input–output
devices such as keyboards, printers,
Digital Codes

➢American Standard Code for Information


Interchange (ASCII) is a 7-bit code, and can at the
most represent 128 characters.
➢Currently defines 95 printable characters
including 26 upper-case letters (A to Z), 26 lower-
case letters (a to z), 10 numerals (0 to 9), and 33
special characters including mathematical
symbols, punctuation marks, and space
characters.
Digital Codes

➢ Unicode is a character encoding standard that assigns


unique numbers to every character, no matter the
language, script and platform.
➢ Each character is assigned a unique code point, a number
that identifies the character.
➢ Unicode characters can be encoded in various formats,
such as UTF-8, UTF-16, and UTF-32.
➢ These encodings determine how the code points are
represented in binary form.
Practice Exercises

1. Find the decimal equivalent of the following:


(a) 110101 (b) 1100.1011 (c) 1001.0101 (d) 1111101
2. Convert each decimal number to binary by using the sum-
of-weights method:
(a) 57 (b) 13 (c) 125 (d) 45.5
3. Convert each decimal number to binary using the repeated
division-by-2 (repeated multiplication-by-2) method:
(a) 21 (b) 0.375 (c) 25.5 (d) 10.625
4. Add the binary numbers:
(a) 1111 and 0101 (b) 01101010, 00001000, 1000001, and
11111111
5. Perform the following binary operations:
(a) 1101 - 0100 (b) 1001 - 0111 (c)110 * 111 (d) 1100 / 011
Practice Exercises

6. Express +19 and -19 as 8-bit numbers in sign-


magnitude, 1’s complement, and 2’s complement.
7. Convert decimal 2591 to hexadecimal
8. Convert the decimal number 9673 to BCD
9. Use ASCII Table to determine the sequence of
ASCII codes required for the following C program
statement and express each code in hexadecimal:
if (y < 8).
Recommended Text

1. Electronic Devices and Circuit Theory by Robert L.


Boylestad and Louis Nashelsky. Prentice Hall
Publications.
2. Electronic Devices, Circuits, and Applications by
Christopher Siu. Springer Nature Switzerland

You might also like