Upload
jonah-bridges
View
267
Download
2
Embed Size (px)
DESCRIPTION
Binary Number System Is a system that uses only the digits 0 and 1 as codes. To represent decimal numbers and letters of the alphabet with the binary code, we have to use different strings of binary digits for each number of letter. Ex: Morse code – dots and dashes Decimal binary counting: Decimal Odometer, Reset-and-Carry, Binary Odometer
Citation preview
Unit - 3
NUMBER SYSTEM AND CODES
Binary Number System Is a system that uses only the digits 0 and 1 as
codes. To represent decimal numbers and letters of the
alphabet with the binary code, we have to use different strings of binary digits for each number of letter.Ex: Morse code – dots and dashes
Decimal binary counting:Decimal Odometer, Reset-and-Carry, Binary Odometer
Why binary numbers are used ? Almost all digital computers and systems are
based on binary (two-state) operation. For instance, the switch shown in figure can be open or closed; therefore, a switch is one example of a natural binary device.
switch Tape rec. Disk drive
Transistor ckt
Table 5.1 - 4-digit Binary numbers
Bit – is the abbreviation for binary digit.
Nibble – binary number with 4 bits
Byte – binary number with 8 bits So, bit = X
Nibble = XXXXByte=XXXXXXXX
Where X may be 0 or 1
Binary-to-Decimal Conversion
Positional notations and weights Binary Weights Streamlined Method Fractions Mixed Numbers
1. Positional Notations and Weights• The position of each digit in a weighted number
system is assigned a weight based on the base or radix of the system.
• The radix of decimal numbers is ten, because only ten symbols (0 through 9) are used to represent any number.
• The column weights of decimal numbers are powers of ten that increase from right to left beginning with 100 =1:
…105 104 103 102 101 100.
We can express any decimal integer (a whole number) in units, tens, hundreds, thousands, so on.
Ex: Decimal number 2495 may written as2495 = 2000+400+90+5In power of 10, this becomes,2495 = 2(103) + 4(102)+9(101)+5(100)
The decimal number system is an example of positional notation, each digit position has a weight or value.
With decimal number the weights are units, tens, hundreds, thousands so on.
The sum of all the digits multiplied by their weights gives the total amount being represented.
Ex: 2 X 1000+4X100+9X10+5X1 = 2945
Binary weights: In a similar way, we can write any binary number
in terms of weights.Ex: binary number 111 becomes
111 = 100 + 10 + 1In decimal numbers, this may be rewritten as
7 = 4 + 2 +1
Each digit position in binary number has a weight.
The least significant digit (right) has a weight of 1. second position from the right has a weight of 2; next 4; and then 8,16,32 so on.
These weights are in ascending powers of 2;Therefore, we can write
7 =1(22) + 1(21) + 1(20) Refer table 5.2 Binary system
2. Streamlined method: We can streamline binary-to-decimal by the
following procedure:
1. Write the binary number2. Directly under the binary number write
1,2,4,8,16…… working from right to left3. If a zero appears in a digit position, cross out
the decimal weight for that position.4. Add the remaining weights to obtain the
decimal equivalent.
3. Fractions:• For fractional decimal numbers, the column
weights are negative powers of ten that decrease from left to right:
. 10-1 10-2 10-3….• For fractional binary numbers, the column
weights are negative powers of two that decrease from left to right:
. 2-1 2-2 2-3 2-4 …
Or decimal equivalence . 0.5 0.25 0.125….
4. Mixed numbers:For mixed numbers ( numbers with an integer and
a fractional part), handle each part according to the rules.
For decimal numbers:
104 103 102 101 100. 10-1 10-2 10-3….
For binary numbers:
22 21 20. 2-1 2-2 2-3 2-4 …
• Refer table 5.3 Powers of 2
Hexadecimal Numbers Are used extensively in microprocessor work, They are much shorter than binary numbers,
so easy to write and remember. Has a base of 16. Although any 16 digits may be used, everyone
uses 0 to 9 and A to F. After reaching 9 in the hexadecimal system,
we can continue counting as A, B, C, D,E,F Hexadecimal Odometer:
Hexadecimal-to-Binary ConversionTo convert a hexadecimal number to a binary number, convert each hexadecimal digit to its 4-bit equivalent.
Ex: 9AF to Binary number Binary-to-Hexadecimal Conversion
Ex: 1000 1100 to Hexadecimal Hexadecimal-to-Decimal Conversion
In hexadecimal number system each digit position corresponds to a power of 16.
The weights of the digit positions in a hexadecimal numbers are as follows:
163 162 161 160 . 16-1 16-2 16-3
Decimal-to-Hexadecimal Conversionhex dabble – Divide decimal number successively by 16
BCD-8421 and BCD-2421codeThe usual method is to follow 8421 encoding which employs conventional route of
weight placements like 8 representing the weight of the 4th place (as 24-1=8), 4 i.e. 23-1 of the 3rd place, 2 i.e. 22-1 of the 2nd place and 1 i.e. 21-1 of the 1st place. The 2421 code is similar to 8421 code except for the fact that the weight assigned to 4th place is 2 and not 8.
The ASCII Code Alphanumeric code to get information into and
out of computer. Known as American Standard Code for
Information Interchange Pronounced as ask’-ee
Using the code The ASCII code is a 7 bit code whose format is
X6 X5 X4 X3 X2 X1 X0
The ASCII Code
Parity bit The ASCII code is used for sending digital data
over telephone line. To catch these error, a parity bit is usually
transmitted along with the original bits. Then a parity checker at the receiver end an test
for even or odd parity, whichever parity has been prearranged between the sender and the receiver.
Since ASCII code uses 7 bits, the addition of a parity bit to the transmitted data produces an 8-bit number in this format:
X7X6 X5 X4 X3 X2 X1 X0 - Ideal length
Excess-3 Code Is an important 4-bit code sometimes used with
Binary – Coded Decimal (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.Ex: convert 12 to Excess-3 code
Useful for BCD arithmetic 9’s Complement of any Excess-3 coded number
can be obtained by complementing each bit.
Excess-3 Code
• Gray code is a code that has a single bit change between one code word and the next in a sequence.
• Gray code is used to avoid problems in systems where an error can occur if more than one bit changes at a time.
• The disadvantage with gray code is that it is not good for arithmetic operation.
0 1 2 3 4 5 6 70 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 11 1
Z o n e N o .S en s o r A B C( Bin ar y c o d ed )
0 1 2 3 4 5 6 70 0 0 0 0 1 0 1 1 0 1 0 1 1 0 11 1 1 0 1 1 0 0
Z o n e N o .S en s o r A B C( G r ay c o d ed )
( a )
( b )
Object moving along a track with sensors (a) binary coded and (b) gray coded.
Gray Code
B 3
B 2
B 1
B 0
( M S B)
( L S B)
B 3
B 2
B 1
B 0
G 3
G 2
G 1
G 0
G 3
G 2
G 1
G 0
( a ) ( b )
(a) Binary to Gray converter and (b) Gray to Binary converter
Gray Code
0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Decimal Binary Gray code
0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
ARITHMETIC CIRCUITS
Binary Addition Four cases to remember
0+0=0 0+1=1 1+0=1 1+1=10
Subscripts 2binary 8octal 10decemal 16hexadecimal
Larger binary numbers 11100 +11010
------------ 110110In last column 1+1+1=10+1=11
Binary Subtraction
Four basic cases 0-0=0 1-0=1 1-1=0 10-1=1
2’s Complement Representation
1’s Complement Inverters produce the 1’s complement. 1’s complement of 1011 is 0100
2’s Complement 2’s complement = 1’s complement + 1. 2’s complement of 1011 is 0100+1=0101.
Sign-magnitude number
In signed magnitude number (–) is represented by 1 and (+) as 0. +101=0101 - 001=1001
Range of sign magnitude number 0 to 255 becomes -127 to +127
2’s Complement Representation Things to remember:
1. Positive numbers always have a sign bit 0, and negative number always have a sign bit 1.
2. Positive numbers are stored in sign-magnitude form.
3. Negative numbers are stored as 2’s complements
4. Taking the 2’s complement is equivalent to a sign change.
2’s Complement Arithmetic 2’s Complement representation has become a
universal code for processing positive and negative numbers.
Addition: Four possible cases:
1. both numbers positive2. a positive number and a smaller negative
number3. a negative number and a smaller positive
number4. both numbers are negative
Conclusion
In every case, 2’s complement addition works.
In other words, as long as positive and negative numbers are expressed in 2’s complement representation, an adding circuit will automatically produce the correct answer.( Assumption: the decimal sum is within the -128 to +127)
Subtraction: Format for subtraction is:
Minuend - Subtrahend
-----------------Difference
Four possible cases:1. both numbers positive2. a positive number and a smaller negative
number3. a negative number and a smaller positive
number4. both numbers are negative
Arithmetic building blocks
Half Adder
Full Adder
Controlled Inverter When the INVERT is low, it transmits the 8-bit
input to the output; When the INVERT is high, it transmits the 1’s
complement.Ex: If the input number is
A7….A0 = 0110 1110
The Adder-Subtracter We can connect full-adders to add or subtract binary
numbers. The circuit is laid out from right to left, similar to the way
we add binary numbers.
ARITHMETIC LOGIC UNIT Arithmetic Logic Unit, popularly called ALU is
multifunctional device that can perform both arithmetic and logic function.
A mode selector input (M) decides whether ALU performs a logic operation or an arithmetic operation
IC 74181 is a 4-bit ALU that can generate 16 different kinds of outputs in each mode selected by four selection inputs S3, S2, S1 and S0.
Functional representation of ALU IC 74181 and Truth Table
Binary Multiplication and Division Multiplication is done with addition instructions and
division with subtraction instruction. Therefore, an adder-subtracter is all that is needed for addition, subtraction, multiplication, and division.
Ex: Multiplication is equivalent to repeated addition 8 X 4 = ?
The first number is called the multiplicand and second no is multiplier.
Multiplying 8 by 4 is the same as adding 8 four times This approach is known as programmed
multiplication by repeated addition. Division – equivalent to repeated subtraction
Arithmetic circuits using HDL We describe a full adder circuit and create a test bench to test it output Sum and Carry (represented by sm and cr in following
Verilog code) is expressed by equations Sum: sm = AB+BC+CA Carry: cr = ABC
module testFullAdder;reg A,B,C;wire sm, cr;fulladder fa1(A,B,C,sm,cr);// Circuit instantiated with fa1initial // simulation begins begin {A,B,C} = 3’b000; //Initialization A=0,B=0,C=0 repeat (7) //repeats following statement seven times #20 {A,B,C}={A,B,C} + 3’b001; //delay of 20 ns and then increment by 1 #20 $finish; // simulation ends after generating 8 combinations of ABC end //total time of simulation 7x20+20=160 nsendmodule
module fulladder(A,B,C,sm,cr); // Description of fulladder Circuitinput A,B,C;output sm,cr;assign sm = (A&B)|(B&C)|(C&A);assign cr = A^B^C;endmodule