Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit - 3 NUMBER SYSTEM AND CODES

Similar presentations


Presentation on theme: "Unit - 3 NUMBER SYSTEM AND CODES"— Presentation transcript:

1 Unit - 3 NUMBER SYSTEM AND CODES

2 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

3 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. Transistor ckt switch Tape rec. Disk drive

4 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 = XXXX Byte=XXXXXXXX Where X may be 0 or 1

5 Binary-to-Decimal Conversion
Positional notations and weights Binary Weights Streamlined Method Fractions Mixed Numbers

6 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:

7 We can express any decimal integer (a whole number) in units, tens, hundreds, thousands, so on.
Ex: Decimal number 2495 may written as 2495 = In 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.

8 The sum of all the digits multiplied by their weights gives the total amount being represented.
Ex: 2 X X100+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 = In decimal numbers, this may be rewritten as 7 =

9 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

10 2. Streamlined method: We can streamline binary-to-decimal by the following procedure: Write the binary number Directly under the binary number write 1,2,4,8,16…… working from right to left If a zero appears in a digit position, cross out the decimal weight for that position. Add the remaining weights to obtain the decimal equivalent.

11 3. Fractions: For fractional decimal numbers, the column weights are negative powers of ten that decrease from left to right: …. For fractional binary numbers, the column weights are negative powers of two that decrease from left to right: Or decimal equivalence ….

12 4. Mixed numbers: For mixed numbers ( numbers with an integer and a fractional part), handle each part according to the rules. For decimal numbers: …. For binary numbers: Refer table 5.3 Powers of 2

13 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:

14 Hexadecimal-to-Binary Conversion
To 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: 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: Decimal-to-Hexadecimal Conversion hex dabble – Divide decimal number successively by 16

15 BCD-8421 and BCD-2421code The 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 of the 3rd place, 2 i.e of the 2nd place and 1 i.e 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.

16 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

17 The ASCII Code

18 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

19 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.

20 Excess-3 Code

21 Gray 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. Object moving along a track with sensors (a) binary coded and (b) gray coded.

22 (a) Binary to Gray converter and (b) Gray to Binary converter

23 Decimal Binary Gray code Gray Code

24 ARITHMETIC CIRCUITS

25 Binary Addition Four cases to remember 0+0=0 0+1=1 1+0=1 1+1=10
Subscripts 2binary 8octal 10decemal 16hexadecimal Larger binary numbers 11100 +11010 110110 In last column 1+1+1=10+1=11

26 Binary Subtraction Four basic cases 0-0=0 1-0=1 1-1=0 10-1=1

27 2’s Complement Representation
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 =0101.

28 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

29 2’s Complement Representation
Things to remember: Positive numbers always have a sign bit 0, and negative number always have a sign bit 1. Positive numbers are stored in sign-magnitude form. Negative numbers are stored as 2’s complements Taking the 2’s complement is equivalent to a sign change.

30 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 positive 2. a positive number and a smaller negative number 3. a negative number and a smaller positive 4. both numbers are negative

31 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)

32 Subtraction: Format for subtraction is: Minuend - Subtrahend
Difference Four possible cases: 1. both numbers positive 2. a positive number and a smaller negative number 3. a negative number and a smaller positive 4. both numbers are negative

33 Arithmetic building blocks
Half Adder Full Adder

34 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 =

35 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.

36 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 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.

37 Functional representation of ALU IC 74181 and Truth Table

38 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

39 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 = ABC module testFullAdder; reg A,B,C; wire sm, cr; fulladder fa1(A,B,C,sm,cr);// Circuit instantiated with fa1 initial // 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 ns endmodule module fulladder(A,B,C,sm,cr); // Description of fulladder Circuit input A,B,C; output sm,cr; assign sm = (A&B)|(B&C)|(C&A); assign cr = A^B^C;


Download ppt "Unit - 3 NUMBER SYSTEM AND CODES"

Similar presentations


Ads by Google