• BCD representation
• Complement
• Fixed Point representation
• Floating point representation
• Arithmetic with complement
• Error detection codes
• Reflected code
• Alpha numeric code
– ASCII,EBCDIC
Number System
• Number of digits used in a number system is called its base or radix (r).• We can categorize number system as below:
– Binary number system (r = 2)
– Octal Number System (r = 8)
– Decimal Number System (r = 10)
– Hexadecimal Number system (r = 16)
Decimal Representation
• We can normally represent decimal numbers in one of following two ways– By converting into binary
– By using BCD codes
• By converting into binary
• Advantage
Arithmetic and logical calculation becomes easy.
Negative numbers can be represented easily.
• Disadvantage
At the time of input conversion from decimal to binary is needed and at the time of output conversion from binary to decimal is needed.
Therefore this approach is useful in the systems where there is much calculation than input/output.
• By Using BCD Codes
• BCD stands for Binary-Coded Decimal.
• The binary number system is the most natural system for a computer, but people are accustomed to the decimal system. So, to resolve this difference, computer uses decimals in coded form which the hardware understands.
• Binary coded decimal (BCD) represents each decimal digit with four bits.
• A BCD number is a four-bit binary group that represents one of the ten decimal digits 0 through 9.
• It is also called natural binary codes because of the 8,4,2 and 1 weights attached to it.
• It is a weighted code.
• Advantage
At the time of input conversion from decimal to binary and at the time of output conversion from binary to decimal is not needed. The main advantage of this code is its ease of conversion to and from decimal.
• Disadvantage
Arithmetic and logical calculation becomes difficult to do. Representation of negative numbers is tricky. It is less efficient than pure binary in the sense that it requires more bits.
Complements
• Complements are used in digital computers for simplifying the subtraction operation and for logical manipulation– There are two types of complements for base r system
• 1) r’s complement
• 2) (r-1)’s complement
– Binary number : 2’s or 1’s complement
– Decimal number : 10’s or 9’s complement
• (r-1)'s complement of a number N is defined as (rn -1) –N Where N is the given number
r is the base of number system
n is the number of digits in the given number To get the (r-1)'s complement fast, subtract each digit of a number from (r-1).
• How do we get (r-1)’s complement …?
• (r-1)′s i.e. 9’s complement of decimal number can be obtained by ((10n - 1)-number)
where n represents the number of digits in given number.
• Example: Find 9’s complement of (1234)10
• Answer:
9′s complement = (104-1)-1234 = 9999-1234 = 8765
r's Complement
• r's complement of a number N is defined as rn –N Where– N is the given number
– r is the base of number system
– n is the number of digits in the given number
To get the r's complement fast, add 1 to the low- order digit of its (r-1)'s complement.
• Note For Fractional digit:
– rn–N
– Where n is number of integer digits
– And fractional digit is not considered
• Example:10’s complement of 134795 is 865205
• Example: Find the 9’s and 10’s complements of 314700.
• Answer:
9’s complement = 685299
10’s complement=685300
Computers must represent everything with 1’s and 0’s, including the sign of a number and fixed/floating point number
Binary/Decimal Point
The position of the binary/decimal point is needed to represent fractions, integers, or mixed integer- fraction number
Two ways of specifying the position of the binary point in a register
1) Fixed Point
2) Floating Point
The binary point is always fixed in one position
• Binary point is assumed to have fixed location, if it is located at the end of the number
A binary point in the extreme left of the register(Fraction : 0.xxxxx)
A binary point in the extreme right of the register(Integer : xxxxx.0)
The binary point is not actually present, but the number stored in the register is treated as a fraction or as an integer
Fixed-Point Representation
• Generally, other locations in binary point position• the second register is used to designate the position of the binary point in the first register
• The floating-point representation of a number has two parts
• 1) Mantissa : signed, fixed-point number
• 2) Exponent : position of binary(decimal) point
• Fixed point number has limited range
• To represent extremely large or extremely small number, we use floating point number (like scientific number)
• Example:
• 0.23X1023(really large number)
• 0.1239X10-10(really small number)
Fixed Point Vs Floating Point Representation
• There is only one way of representing positive numbers with sign-bit 0 but when number is negative the sign is represented by 1 and rest of the number may be represented in one of three possible ways– Signed-magnitude representation
– Signed-1’s complement representation
– Signed-2’s complement representation
• Signed Magnitude Notation
• Complement only the sign bit
• Example:
+9 0 001001
-9 1 001001
* MSB for Sign “0” is plus + “1” is minus -
• Signed 1’s complement Notation
• Complement all the bits including sign bit.• Example:
+9 0 001001
-9 1 110110
• Signed 2’s complement Notation
• Take the 2's complement of the number, including its sign bit• Example:
+9 0 001001
-9 1 110111
Subtraction of unsigned Numbers
• When subtraction is implemented in digital hardware, borrow-method is found to be less efficient than the method that uses complements.• The subtraction of two n-digit unsigned numbers M-N (N≠0) in base r can be done as follows:
1. Add the minuend, M, to the r’s complement of the subtrahend, N. This performs M + (rn − N) = M − N + rn.
2. If M≥N, sum will produce an end carry, rn, which can be discarded; the result is M − N.
3. If M
Arithmetic addition and subtraction of signed numbers
– Arithmetic Subtraction
• Subtraction is changed to an Addition– (± A) - (+ B) = (± A) + (- B)
– (± A) - ( - B) = (± A) + (+ B)
Overflow
• Two numbers of n digits each are added and the sum occupies n+1 digits• n + 1 bit cannot be accommodated in a register with a standard length of n bits(many computer detect the occurrence of an overflow, and a corresponding F/F is set)
• An overflow may occur if the two numbers added are both positive or both negative
– When two unsigned numbers are added
» an overflow is detected from the end carry out of the MSB position
– When two signed numbers are added
» the MSB always represents the sign
» the sign bit is treated as part of the number
» the end carry does not indicate an overflow
Overflow Demonstration
Overflow Detection
Detected by observing the carry into the sign bit position and the carry out of the sign bit position If these two carries are not equal, an overflow condition is produced(Exclusive-OR gate = 1)
Other Binary Codes
• Gray Code• Self complementing code
• Weighted Code(2421 and 8421 codes)
• Excess 3 code
• EBCDIC
• It is a binary coding scheme used to represent digits generated from a mechanical sensor that may be prone to error.
• Used in telegraphy in the late 1800s, and also known as "reflected binary code”.
• The reflected binary or Gray code is used to represent digital data converted from analog information.
• Non-weighted code
• In Gray code, there is only one bit location different between two successive values, which makes mechanical transitions from one digit to the next less error prone.
• The Gray code’s most important characteristic is that only one digit changes as you increment or decrement the count.
• The Gray code is commonly associated with input/output devices such as an optical encoder of a shaft’s angular position.
• The Gray code is used in applications where the normal sequence of binary numbers may produce an error or ambiguity during the transition from one number to the next.
• Conversion from Binary to Gray code:
Step 1: Write MSB of given Binary number as it is.
Step 2: Ex-OR this bit with next bit of that binary number and write the result.
Step 3: Ex-OR each successive sum until LSB of that binary number is reached.
Eg.: (1010011)2 to its equivalent Gray code.
Self Complementing Code
• The 2421 code and the excess-3 have the advantage that they are self-complementing. But excess-3 code is not weighted.• Self complementing codes are the codes that have the property that 9's complement of a decimal no. is obtained directly by replacing 1s by 0s and 0s by 1s i.e. by complementing each bit in the pattern.
• Self-complementing binary codes are those whose members complement on themselves.
• For a binary code to become a self-complementing code, the following two conditions must be satisfied:
– The complement of a binary number should be obtained from that number by replacing 1’s with 0’s and 0’s with 1’s (already stated procedure).
– The sum of the binary number and its complement should be equal to decimal 9.
Weighted Code
• In weighted code, each digit position has a weight or value.• The sum of all digits multiplied by a weight gives the total amount being represented.
• We can express any decimal number in tens, hundreds, thousands and so on.
• Eg:- Decimal number 4327 can be written as
4327= 4000+300+20+7
• In the power of 10, it becomes
4327= 4(10³)+3(10²)+2(10¹)+7(100)
• BCD or 8421 is a type of weighted code where each digit position is being assigned a specific weight.
2421 Code
• This is a weighted code, its weight are 2,4,2 and 1.• A decimal number is represented in 4 bit form and the total four bits weight is 2+4+2+1=9.
• Hence the 2421 code represents the decimal numbers from 0 to 9.
• This is also a self complementary code.
THE EXCESS-3 CODE
• Add 3 to each digit of decimal and convert to 4-bit binary form• A BCD code (not 8421 BCD)
• It is an important BCD code , is a 4 bit code and used with BCD numbers
• To convert any decimal numbers into its excess-3 form ,add 3 to each decimal digit and then convert the sum to a BCD number
• As weights are not assigned, it is a kind of non weighted codes.
THE EXCESS-3 CODE
Alphanumeric Representation
• Alphanumeric codes are codes used to encode the characters of alphabet in addition to the decimal digits.• Alphanumeric characters is a set of elements that include
– 26 alphabets with capital and small letters
– Numbers from 0 to 9
– Punctuation marks and other symbols
– special characters such as $, %, + etc.
• Alphanumeric codes represent numbers and alphabetic characters.
– They also represent other characters such as punctuation symbols and instructions for conveying information.
Alphanumeric Codes
• They are used primarily for transmitting data between computers and its I/O devices such as printers, keyboards and video display terminal• Therefore instead of using only single binary bits, a group of bits is used as a code to represent a symbol
ASCII
• ASCII is acronym for American Standard Code for Information Interchange• Standard alphanumeric binary code is ASCII
• Represents numbers, letters, punctuation marks and control characters
• Standard ASCII is a 7-bit code (128 characters)
• In the ASCII character set, each binary value between 0 and 127 represents a specific character.
• Extended ASCII (IBM ASCII), an 8-bit code, is also very popular
• Extended ASCII adds graphics and math symbols to code (total of 256 symbols)
• In general, ASCII works by assigning standard numeric values to letters, numbers, punctuation marks and other characters such as control codes.
• An uppercase "A," for example, is represented by the decimal number 65."
EBCDIC-(Extended Binary Coded Decimal Interchange Code)
• EBCDIC is eight bits, or one byte, wide.• This is a coding system used to represent characters-letters, numerals, punctuation marks, and other symbols in computerized text.
• A character is represented in EBCDIC by eight bit.
• Total 256 characters are possible, however all are not used.
• There is no parity bit used to check error in this code set.
• Single byte EBCDIC takes up eight bits, which are divided in two pieces.
– The first four bits are called the zone and represent the category of the character, whereas the last four bits are the called the digit and identify the specific character
Error-Detection codes
• Binary information transmitted through some form of communication medium is subject to external noise that could change bits from 1 to 0, and vice versa.• An error detection code is a binary code that detects digital errors during transmission.
• One of the most common ways to achieve error detection is by means of a parity bit.
• A parity bit is the extra bit included with a binary message to make the total number of 1's either even or odd.
• 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.
• During the transmission of information from one location to another, an even parity bit is generated in the sending end for each message transmission.
– The message, together with the parity bit, is transmitted to its destination.
• The parity of the received data is checked in the receiving end.
– If the parity of the received information is not even, it means that at least one bit has changed value during the transmission.
Parity generator
• Parity generator and checker networks are logic circuits constructed with exclusive-OR functions• At the sending end the message is applied to a parity generator, where the required parity bit is generated.
• The message including the parity bit is transmitted to its destination.
• Consider a 3- bit message to be transmitted with an odd parity bit.
• At the sending end, the odd parity is generated by a parity generator circuit.
Parity checker
• At the receiving end, all the incoming bits are applied to a parity checker that checks the proper adopted.• An error is detected if the checked parity does not conform to the adopted parity
• Considers original message as well as parity bit