convert a two s complement number back into a recognizable magnitude.

Similar documents
ENGIN 112 Intro to Electrical and Computer Engineering

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

Chapter 1 CSCI

CHAPTER 2 NUMBER SYSTEMS

CprE 281: Digital Logic

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

hexadecimal-to-decimal conversion

Hakim Weatherspoon CS 3410 Computer Science Cornell University

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

Binary addition example worked out

Conversions between Decimal and Binary

COMBINATIONAL LOGIC FUNCTIONS

Chapter 5 Arithmetic Circuits

Combinational Logic Design Arithmetic Functions and Circuits

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

Combinational Logic. By : Ali Mustafa

Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

THE LOGIC OF COMPOUND STATEMENTS

ECE380 Digital Logic. Positional representation

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

Chapter 2 Combinational Logic Circuits

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

Numbers and Arithmetic

Carry Look Ahead Adders

Modern Algebra Prof. Manindra Agrawal Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Logic. Combinational. inputs. outputs. the result. system can

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

of Digital Electronics

Fundamentals of Digital Design

Binary Multipliers. Reading: Study Chapter 3. The key trick of multiplication is memorizing a digit-to-digit table Everything else was just adding

CPE100: Digital Logic Design I

Digital Techniques. Figure 1: Block diagram of digital computer. Processor or Arithmetic logic unit ALU. Control Unit. Storage or memory unit

ECE/CS 250 Computer Architecture

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

Chapter 03: Computer Arithmetic. Lesson 03: Arithmetic Operations Adder and Subtractor circuits Design

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

Numbers and Arithmetic

Design of Sequential Circuits

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

Four Important Number Systems

UNIT II COMBINATIONAL CIRCUITS:

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

CMP 334: Seventh Class

Systems I: Computer Organization and Architecture

Week No. 06: Numbering Systems

CSE 241 Digital Systems Spring 2013

Why digital? Overview. Number Systems. Binary to Decimal conversion

ECE260: Fundamentals of Computer Engineering

Module 2. Basic Digital Building Blocks. Binary Arithmetic & Arithmetic Circuits Comparators, Decoders, Encoders, Multiplexors Flip-Flops

Building a Computer Adder

CHAPTER 12 Boolean Algebra

CS 140 Lecture 14 Standard Combinational Modules

The goal differs from prime factorization. Prime factorization would initialize all divisors to be prime numbers instead of integers*

Chapter 1: Logic systems

Computer organization

ALU (3) - Division Algorithms

Adders - Subtractors

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Chapter 5. Digital systems. 5.1 Boolean algebra Negation, conjunction and disjunction

STEP Support Programme. Hints and Partial Solutions for Assignment 17

We say that the base of the decimal number system is ten, represented by the symbol

What s the Deal? MULTIPLICATION. Time to multiply

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

ECE 372 Microcontroller Design

CprE 281: Digital Logic

Lecture 5: Arithmetic

XOR - XNOR Gates. The graphic symbol and truth table of XOR gate is shown in the figure.

Ex code

CprE 281: Digital Logic

Lecture 2 Review on Digital Logic (Part 1)

Lecture 8: Sequential Multipliers

Computer Architecture. ESE 345 Computer Architecture. Design Process. CA: Design process

Physics 310 Lecture 10 Microprocessors

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

Chapter 1 :: From Zero to One

ELCT201: DIGITAL LOGIC DESIGN

Binary addition by hand. Adding two bits

Introduction to Digital Logic

DIGITAL TECHNICS. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute

CSCI 255. S i g n e d N u m s / S h i f t i n g / A r i t h m e t i c O p s.

SAU1A FUNDAMENTALS OF DIGITAL COMPUTERS

Representing signed numbers in Two s Complement notation

Chapter 2 Combinational Logic Circuits

Total Time = 90 Minutes, Total Marks = 100. Total /10 /25 /20 /10 /15 /20

Logic Theory in Designing of Digital Circuit & Microprocessor

EECS150 - Digital Design Lecture 24 - Arithmetic Blocks, Part 2 + Shifters

Save from: cs. Logic design 1 st Class أستاذ المادة: د. عماد

CSC9R6 Computer Design. Practical Digital Logic

Number System conversions

Part 1: Digital Logic and Gates. Analog vs. Digital waveforms. The digital advantage. In real life...

Department of Electrical & Electronics EE-333 DIGITAL SYSTEMS

Data Converter Fundamentals

DSP Design Lecture 2. Fredrik Edman.

Binary logic consists of binary variables and logical operations. The variables are

Transcription:

1 INTRODUCTION The previous lesson introduced binary and hexadecimal numbers. In this lesson we look at simple arithmetic operations using these number systems. In particular, we examine the problem of representing negative numbers. YOUR AIMS On completing this lesson you should be able to: add and subtract binary numbers describe two ways in which negative numbers can be represented by a binary code perform arithmetic operations using two s complement notation convert a two s complement number back into a recognizable magnitude. STUDY ADVICE Again, this is a short unit in terms of text but it will require considerable time to complete all the examples and Self-Assessment Questions. Have to hand a pencil and scrap paper!

2 ADDITION OF BINARY NUMBERS In principle, binary numbers are added in exactly the same way as in denary addition but remember we are working to a base of two! This means that (1 + 1) will generate a carry. The rules of binary addition are summarised below: 0 0 1 1 + 0 + 1 + 0 + 1 0 1 1 0 carry 1 You may find it worthwile to write these rules down several times so that you remember them. Then study the following examples. Example 1 Add the binary numbers 1010 and 0011. 1 0 1 0 + 0 0 1 1 1 1 0 1 carry The bits in each column are added together and any carry bit generated is added into the column on the left.

3 Example 2 Add the binary numbers 1011 and 0011. * 1 0 1 1 + 0 0 1 1 1 1 1 0 carry In this example the column marked with an asterisk represents the addition (1 + 1 + 1) = 11. This means that 1 is entered into this column and one is carried over to the next most significant column. Example 3 Perform 11101110 2 + 01101101 2 1 1 1 0 1 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 carry A harder example, this, with lots of carries. Note that the most significant column also generates a carry. Microprocessors have a carry flag that can be set when an overflow carry is generated more on this in a later lesson.

4 BINARY SUBTRACTION There is no theoretical reason why binary numbers cannot be subtracted using the same rules as for denary subtraction, i.e. starting with the least significant column we subtract one bit from another. The rules for binary subtraction will then be: 0 1 1 0 0 0 1 1 (borrow 1 from left hand column) 0 1 0 1 In the fourth rule, 1 from 0 won t go and we have to borrow a bit from the adjacent column. This now forms the equivalent of (2 1) = 1. Example 4 Subtract 0111 from 1111. 1 1 1 1 0 1 1 1 1 0 0 0 Note that the answer can be checked by adding the result to the number subtracted. 0 1 1 1 + 1 0 0 0 1 1 1 1

5 Example 5 Subtract 0011 from 1101. 1 1 0 1 (In column 2 we have to borrow 0 0 1 1 from column 3.) 1 0 1 0 borrow This is as far as we shall go in binary subtraction. The reason for this is that computers do not perform subtraction in this way. There are two reasons why they do not: (a) Binary addition is carried out in the arithmetic logic unit (ALU) built into the CPU. The addition is done by special adder hardware. If subtraction were to be done in the conventional way then subtractor hardware would also be required. (b) Subtraction can give rise to negative results. Thus we need a means of representing positive and negative numbers. Conventionally we do this by using the symbols + and. We must remember, however, that a binary machine will only recognise two symbols (namely 0 and 1 ). We cannot therefore use extra symbols to denote a number s sign.

6 REPRESENTATION OF NEGATIVE NUMBERS Two methods will be considered. THE SIGN-MAGNITUDE METHOD This method is widely used in data communications systems. The magnitude of a number is its value, ignoring its sign. Thus the magnitude of +3 is 3 and -8 is 8. The magnitude of minus one hundred is equal to the magnitude of plus one hundred. In the sign magnitude method, the sign of a binary number is given by the MSB. The remaining bits give the magnitude of the number. If positive numbers are represented by the MSB being set to 0, then negative numbers are represented by the MSB being set to 1. To illustrate the idea, the binary equivalents of -5 to +5 are listed below (using 1 byte numbers): SIGN BIT MAGNITUDE -5 1 0000101-4 1 0000100-3 1 0000011-2 1 0000010

7-1 1 0000001-0 1 0000000 +0 0 0000000 +1 0 0000001 +2 0 0000010 +3 0 0000011 +4 0 0000100 +5 0 0000101 As a matter of curiosity, note that this method gives two zeros, 10000000 (minus zero) and 00000000 (plus zero)! This, however, does not cause any problems. Also, there is, as a matter of fact, no hard and fast rule as to whether a 1 or a 0 is used to represent a positive number. Which convention is adopted will depend upon the particular system. The advantage of the method is the simplicity with which it allows the magnitude of the number to be quickly established. A serious disadvantage though, is that the method cannot easily be used for binary arithmetic. Consider the following examples.

8 Example 6 Add (+3) to ( 3) using binary signed numbers +3 = 00000011 and 3 = 10000011 0 0 0 0 0 0 1 1 + 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 0 Clearly the result should have been zero ((+3) + ( 3) = 0) but the addition has come up with 6. Example 7 Add ( 5) to (+2). 5 = 10000101 and +2 = 00000010 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 1 This time the answer is 7 and not 3 as it should be. You may care to try a few examples yourself and I am sure you will soon be convinced that this method is quite hopeless for arithmetic. Nevertheless it does have the value of simplicity and is used in systems where the data does not have to be processed arithmetically. The sign-magnitude method is used, for example, in the PCM (plus code modulation) system of digital audio applications.

9 THE TWO S COMPLEMENT METHOD The one s complement of a binary number is obtained by changing all the 1 s to 0 s and vice versa. (This process is known as INVERTING the number.) A few examples of binary numbers and their one s complements are given below. NUMBER ONE S COMPLEMENT 0 0 0 0 1 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 Note that in each of the above examples adding the binary number to its complement always yields 1111. Moreover we note that in performing the operation of adding a binary number to its complement +1 will always yield 0000 or zero. The two s complement of a binary number is formed by taking the one s complement and adding 1 to it. Example 8 Find the two s complement of 14. Express the answer as an 8 bit number. 14 10 = 00001110 One s complement = 11110001 Two s complement = ( one s complement + 1)

10 = (11110001 + 1) = 11110010 Example 9 Find the two s complement of 25. 25 10 = 00011001 2 Two s complement = (11100110 + 1) = 11100111 We have shown above that adding a binary number to its one s complement +1 will always yield 0000 or zero. As the one s complement +1 is in fact the two s complement of the binary number then we can write: N + N = 0 where N is the binary number and N is its two s complement. Thus N = N Thus two s complement form can be used to represent the negative of a binary number that can be used in arithmetic operations. It may be a bit tricky for us to use and recognise the two s complement form, but relatively simple arithmetic circuits in the CPU are quite at home with them. To convince yourself that the two s complement representation of binary numbers works, study the following examples.

11 Example 10 Using the two s complement method perform the operation (25 14). (25 14) may be rewritten as (25 + ( 14)). The procedure is to represent ( 14) in two s complement form and then add this to 25. 25 10 = 0 0 0 1 1 0 0 1 add ( 14 10 ) = 1 1 1 1 0 0 1 0 [1] 0 0 0 0 1 0 1 1 carry As we are working in 8 bit numbers, the carry one is ignored. The result is, therefore, 00001011 2 = 11 10. Example 11 Using the two s complement representation show that 25 25 = 0. 25 = 0 0 0 1 1 0 0 1 add ( 25) = 1 1 1 0 0 1 1 1 [1] 0 0 0 0 0 0 0 0 carry Again, the carry bit is ignored and a zero result is obtained.

12 Example 12 Using the two s complement representation evaluate (14 25). 14 = 0 0 0 0 1 1 1 0 add ( 25) = 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 1 This answer highlights one of the difficulties of the two s complement form. In the complement system all negative numbers have a MSB of 1, so we know our result is negative, but the magnitude of the number is by no means obvious! Before attempting to evaluate, in denary, the solution to example 12, let's investigate our new systems a little more closely. Initially, for simplicity, we will use 4 bit signed numbers. This gives a numbering range of ( 8) to (+7) as indicated on the number line shown below. DENARY 8 7 6 5 4 3 2 1 0 +1 +2 +3 +4 +5 +6 +7 1000 1001 1010 1011 1100 1101 1110 1111 ( 8+0) ( 8+1) ( 8+2) ( 8+3) ( 8+4) ( 8+5) ( 8+6) ( 8+7) 0000 0001 0010 0011 0100 0101 0110 0111 BINARY The clue to evaluating the magnitude of a negative number represented in two s complement form is to note that, for example, ( 3) = ( 8 + 5). Looking at the number here we see that ( 3) = 1101. Thus the two s complement form can be regarded as consisting of a mixture of two numbers: (a) a negative number represented by the MSB and equal to ( 2 n 1 ) where n is the bit length of the number

13 (b) a positive number evaluated from the remaining bits. NEGATIVE NUMBER POSITIVE NUMBER 1 1 0 1 ( 2n 1 ) = ( 2 3 ) = 8 (2 2 + 2 0 ) = 5 The result is, of course, obtained by adding the two numbers together. We are now in a position to return to Example 12. The result is an 8-bit signed number and thus the number range will be from ( 128) to (+127). This range was evaluated using the formulae: (a) lower limit = ( 2 n 1 ) giving 128 for n = 8 (b) upper limit = (2 n 1 1) giving +127 for n = 8 Splitting (11110101) into two parts yields: 11110101 ( 2 8 1 ) = 128 (2 6 + 2 5 + 2 4 + 2 2 + 2 0 ) = 117 The answer, in denary is, therefore, ( 128 + 117) = 11 The system works!

14 A SIMPLE TRICK! Before concluding this lesson we introduce you to a simple rule for converting binary numbers into a two s complement form, which can save a lot of work. The rule is: (a) Write down the binary number, starting with the LSB, up to and including the first 1. (b) Invert the remaining bits. Consider example 13. Example 13 Write down the two s complement of 01110010. 01110010 invert these bits to give 'up to and including the first '1" gives '1 0 0 0 1 1' '1 0' Thus two s complement of 01110010 is 10001110. Example 14 Perform the arithmetic operation (17 97) in binary. Express your answer in two s complement form and then convert it to denary. Work in 8 bit numbers.

15 17 = 00010001 97 = 01100001 2 ( 97) = 10011111 (in two s complement) Adding ( 97) to (+17): 0 0 0 1 0 0 0 1 + 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 0 Thus in two s complement the result is 10110000 (which is clearly negative as the MSB is set to 1 ). Converting this to denary: 10110000 = ( 2 8 1 ) + (2 5 + 2 4 ) = ( 128 + 48) = 80 The trick can also be used in reverse to convert a negative number expressed in two complement form back into a magnitude. Consider the result to example 14, namely 10110000. In reversing the trick we: (a) write down the number up to and including the first 1 (yielding 10000) (b) invert all the other bits (giving 01010000 ). The magnitude is thus 01010000 = 80 As we know we are dealing with a negative number the answer is 80.

16 Which method you use (the more formal [ 2 n -1 + (positive number)] or the trick ) is entirely up to you there is little to choose between them in terms of speed of conversion. This completes our work on computer arithmetic, but to further develop and consolidate your understanding try the following Self-Assessment Questions.

17 SELF-ASSESSMENT QUESTIONS 1. Add the following binary numbers. In each case express the answer as an 8 bit number. In each case state if a carry is generated beyond the MSB. (a) 0 0 0 0 1 1 1 1 + 0 0 0 0 1 0 1 0 (b) 1 0 1 0 1 0 1 0 + 1 1 0 1 0 1 0 1 (c) 0 1 1 1 1 0 0 1 + 1 0 1 1 0 0 0 1 (d) 0 0 0 0 0 0 1 0 + 1 1 1 1 1 1 1 1 2. Add the following HEX numbers by converting to binary. Express the answer in HEX. (a) 08 + 03 (b) 0F + 02 (c) 0ABC + DA0E 3. Convert the following numbers to two s complement form: (a) 0 0 0 0 0 0 0 1 (b) 0 1 1 0 1 0 0 0 (c) 0 0 1 1 1 1 0 0 (d) 0 1 1 1 1 1 1 1

18 4. In the table below, negative numbers are represented by the two s complement form. Identify the odd negative numbers: (a) 0 0 1 1 0 1 0 1 (b) 0 0 0 0 0 0 0 1 (c) 1 0 0 0 0 0 0 1 (d) 1 0 1 0 1 0 1 0 (e) 0 1 0 1 0 1 0 1 (f) 1 0 0 1 0 1 1 0 (g) 1 0 1 0 1 1 1 1 (h) 0 0 1 1 0 0 0 1 (i) 1 0 0 0 0 0 1 0 (j) F8 (k) 8A (l) CB 5. A sixteen bit microprocessor is to be used to perform arithmetic operations using signed numbers in two s complement form. Calculate the numbering range that can be represented using 16 bits. 6. Convert the denary numbers in (a) (d) to 8 bit binary numbers and evaluate using the two s complement method. Leave your answers in binary form. (a) 17 8 (b) 126 33 (c) 4 48 (d) 97 125 7. When performing an arithmetic operation using signed numbers a microprocessor gives the result F6. Express this in denary. 8. Subtract C006 from A0F7 using two s complement arithmetic. Express the answer in Hex.

19 9. Perform the operations: (a) 7A + 85 (b) 7A 7B Comment upon the result. 10. State the effect upon the magnitude of an 8 bit binary number by: (a) shifting each bit one position to the left (b) shifting each bit one position to the right. The answers are on page 20.

20 ANSWERS TO SELF-ASSESSMENT QUESTIONS 1. (a) 0 0 0 0 1 1 1 1 + 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 1 (no carry) (b) 1 0 1 0 1 0 1 0 + 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 (carry generated) (c) 0 1 1 1 1 0 0 1 + 1 0 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 (carry generated) (d) 0 0 0 0 0 0 1 0 + 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 (carry generated) 2. (a) 0 8 0 0 0 0 1 0 0 0 + 0 3 0 0 0 0 0 0 1 1 0 B 0 0 0 0 1 0 1 1 (b) 0 F 0 0 0 0 1 1 1 1 + 0 2 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 1

21 (c) 0ABC 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 + DA0E 1 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0 E4CA 1 1 1 0 0 1 0 0 1 1 0 0 1 0 1 0 3. (a) Using the trick the complements may be written straight down: (a) 1 1 1 1 1 1 1 1 (b) 1 0 0 1 1 0 0 0 (c) 1 1 0 0 0 1 0 0 (d) 1 0 0 0 0 0 0 1 4. Negative odd numbers will have MSB and LSB at 1. Therefore (c), (g) and (l) are odd negative numbers. 5. The numbering range will extend from ( 2 n 1 ) to (2 n 1 1) where n = 16. Thus the range is ( 2 15 ) to (2 15 1) = 32768 to 32767 6. (a) 17 = 0 0 0 1 0 0 0 1 8 = 0 0 0 0 1 0 0 0 ( 8) = 1 1 1 1 1 0 0 0 (17) 0 0 0 1 0 0 0 1 + ( 8) 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 1 The carry one is ignored and thus the answer is 00001001.

22 (b) 126 = 0 1 1 1 1 1 1 0 33 = 0 0 1 0 0 0 0 1 ( 33) = 1 1 0 1 1 1 1 1 (126) 0 1 1 1 1 1 1 0 + ( 33) 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 0 1 Again, the carry is ignored, leaving the result 01011101. (c) 4 = 0 0 0 0 0 1 0 0 48 = 0 0 1 1 0 0 0 0 ( 48) = 1 1 0 1 0 0 0 0 (4) 0 0 0 0 0 1 0 0 + ( 48) 1 1 0 1 0 0 0 0 1 1 0 1 0 1 0 0 (d) 97 = 0 1 1 0 0 0 0 1 125 = 0 1 1 1 1 1 0 1 ( 125) = 1 0 0 0 0 0 1 1 (97) = 0 1 1 0 0 0 0 1 + ( 125) = 1 0 0 0 0 0 1 1 1 1 1 0 0 1 0 0

23 7. F6 = 11110110 which is obviously negative. Thus 11110110 = ( 2 7 ) + (2 6 + 2 5 + 2 4 + 2 2 + 2 1 ) = 128 + 118 = 10 (N.B. You will see in later work that this kind of conversion needs to be applied when using certain types of computer instructions.) 8. A0F7 = 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1 1 C006 = 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 ( C006) = 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 A0F7 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1 1 + ( C006) 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 E0F1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 9. (a) 7A = 0 1 1 1 1 0 1 0 85 = 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 (b) 7B = 0 1 1 1 1 0 1 1 ( 7B) = 1 0 0 0 0 1 0 1 (7A) = 0 1 1 1 1 0 1 0 + ( 7B) = 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1

24 Comment The answers are identical. Note, however, that in (a) we are using unsigned, eight bit numbers, whilst in (b) signed numbers are being used. Hence in converting (a) back to denary we would read it as +255 whereas (b) represents 1. 10. The table below shows the effect of shifting an 8 bit binary number to the left. The effect is to double the number. A right shift will halve the number. This is an obvious consequence of positional notation. 0 0 0 0 0 0 0 1 (1) 0 0 0 0 0 0 1 0 (2) 0 0 0 0 0 1 0 0 (4) 0 0 0 0 1 0 0 0 (8) 0 0 0 1 0 0 0 0 (16) 0 0 1 0 0 0 0 0 (32) 0 1 0 0 0 0 0 0 (64) 1 0 0 0 0 0 0 0 (128) A microprocessor will have instructions that permit us to shift left or shift right which are useful in, for example, binary multiplication. Note, however, that if we were using signed numbers then we would have to be careful. For instance, the last result of the above table would then be negative!

25 SUMMARY (a) The rules of binary addition are: 0 0 1 1 +0 +1 +0 1 0 1 1 0 carry 1 to left hand column (b) The rules of binary subtraction are: 0 1 1 0 0 0 1 1 0 1 0 1 borrow 1 from left hand column (c) Two common ways of representing negative numbers are: (i) Sign-magnitude method when the MSB gives the sign of the number and the remaining bits the magnitude. (ii) Two s complement method obtained by inverting the number and adding 1 to the result. In the next lesson we consider some simple hardware which can be used to perform simple operations on binary data.