Number Systems (2.1.1)

Similar documents
Introduction to Computers and Programming. Numeric Values

COMP Overview of Tutorial #2

Number System. Introduction. Decimal Numbers


A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Signed Binary Numbers

World Inside a Computer is Binary

CS & IT Conversions. Magnitude 10,000 1,

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CS 261 Fall Mike Lam, Professor Integer Encodings

unused unused unused unused unused unused

Number representations

CS101 Lecture 04: Binary Arithmetic

THE LOGIC OF COMPOUND STATEMENTS

COMP2611: Computer Organization. Data Representation

Advanced Computer Architecture-CS501

Chapter 3: Arithmetic for Computers

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Chapter 4. Operations on Data

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Representation of Non Negative Integers

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Introduction to Computer Science-103. Midterm

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Chapter 10 Binary Arithmetics

3.1 DATA REPRESENTATION (PART C)

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

Chapter 2: Number Systems

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Learning the Binary System

Binary. Hexadecimal BINARY CODED DECIMAL

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Number Systems. Both numbers are positive

BINARY SYSTEM. Binary system is used in digital systems because it is:

Chapter 1 Review of Number Systems

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Computing Basics. 1 Sources of Error LECTURE NOTES ECO 613/614 FALL 2007 KAREN A. KOPECKY

Computer Organisation CS303

Home brewed code for conversion of single precision float value to string

Lecture 2: Number Systems

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

CHAPTER 5: Representing Numerical Data

Data Representation 1

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Floating Point Representation in Computers

Binary Codes. Dr. Mudathir A. Fagiri

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Introduction to Computer Science. Homework 1

Chapter 4. Combinational Logic

Digital Fundamentals

Chapter 1. Numeric Artifacts. 1.1 Introduction

MC1601 Computer Organization

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Number System (Different Ways To Say How Many) Fall 2016

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

CS 64 Week 1 Lecture 1. Kyle Dewey

Module 2: Computer Arithmetic

Read this before starting!

Numerical computing. How computers store real numbers and the problems that result

Data Representation in Computer Memory

Numerical Representations On The Computer: Negative And Rational Numbers

Number Systems CHAPTER Positional Number Systems

Signed umbers. Sign/Magnitude otation

Floating Point Arithmetic

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

EE 109 Unit 6 Binary Arithmetic

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Numerical Representations On The Computer: Negative And Rational Numbers

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Final Labs and Tutors

CHW 261: Logic Design

Binary Arithmetic. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T.

Fundamentals of Programming (C)

COMP 122/L Lecture 2. Kyle Dewey

More Programming Constructs -- Introduction

Lecture 8: Addition, Multiplication & Division

FLOATING POINT NUMBERS

Inf2C - Computer Systems Lecture 2 Data Representation

SIGNED AND UNSIGNED SYSTEMS

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Introduction to Scientific Computing Lecture 1

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

Level ISA3: Information Representation

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 3 DLD P VIDYA SAGAR

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Binary Values. CSE 410 Lecture 02

Transcription:

Number Systems (2.1.1) Concept of a register. Operations of register, Complementation, Ranges, Left and right shifts, Addition of two binary number, Numerical overflow, 2 s complement representation, Binary addition and subtraction (by complementation followed by addition) in 2 s complement. Concept of a Register A register is a small amount of very fast computer memory used to speed up the execution of computer programs. These are used to offer storage for most commonly used values, so they can be quickly accessed when they are needed. Modern computers work by loading information into the registers, operating on this data, and then loading it back to the main memory. This is often referred to as load-store architecture. There are various types of registers such as data-register, address-register and instruction-register which will be discussed in the CPU section. Ms. P. Sullivan Page 1 of 7

Complementation Addition can also be used on binary numbers. The following are some basic additions and their results: 0+ 0+ 1+ 1+ 0 1 0 1 0 1 1 10 Please note that 1 2 + 1 2 + 1 2 = 11 2. If we add 1 10 + 1 10 + 1 10 using decimals, the answer would be 3 10. If we convert 3 10 to binary it would be represented as 11 2. The following are some addition examples. 100+ 1001+ 111+ 011 0011 001 111 1100 1000 In the third example 111 2 + 001 2 the result is 1000 2 this is one bit more than any of the original numbers, which are made up of three bits. In this case the correct answer 1000 2 is noted down, but in some cases where the number of bits is restricted a numerical overflow occurs, which means that more bits than there are available will be used. Complementation is a method of representing positive and negative numbers. This system requires numbers to be represented by a fixed number of bits. There are two forms of complementation, one s complement and two s complement. Two s complement is preferred because subtraction can be performed by adding the two s complement of the number to be subtracted. One s complement is used to represent negative numbers. Assume that the number 45 10 will be used for this example. 45 10 in binary using 8 bits can be noted down as 00101101 2. However, if the number 45 10 was to change to -45 10, by using one s complement its binary representation must also be changed. This can be changed by simply converting the number, that is 0s will become 1s and 1s will become 0s. So, in this case 00101101 2 will become 11010010 2. Ms. P. Sullivan Page 2 of 7

In two s complement apart from inverting the bits, the result is increased by one. So by using the previous example to represent -45 10, first forty-five (in binary) 00101101 2 is changed using one s complement, i.e. 11010010 2. Then a one is added, which makes the number 11010011 2. This makes it easier to subtract numbers in binary. It is imperative that both numbers have the same amount of bits. One cannot subtract two numbers if one is made up of 6-bits, and the other of 8-bits. In which case the number with 6-bits, must have two zeros added in front before any complementation to become an 8-bit number. Example 1 30 10 17 10 in binary using 8 bits can be worked out as follows. First both decimal numbers are converted to binary. 30 10 00011110 2 17 10 00010001 2 Next, two s complement is applied on the negative number which in this case is 17 10. 00010001 2 11101110 2 + 1 2 11101111 2 Now, the final step is to add the two numbers. 00011110 2 + 11101111 2 100001101 2 Now since we have started with a register of 8 bits the result must also have 8 bits. So the first number is dropped, so the answer is 00001101 2. Ms. P. Sullivan Page 3 of 7

Ranges Ranges are used to determine the lowest and the highest values which can be represented using a fixed amount of bits. This is commonly used in memory addressing, in which by having a register size, the maximum and minimum number of locations can be derived. In this case, we will discuss two types of ranges, one using normal binary, and the other using two s complement. Range using Normal Representation What is the range of numbers which can be represented using 8-bits? Since we have 8 Bits, the maximum value represented in binary is 11111111 2 and the smallest is 00000000 2. If we convert these numbers to decimal we end up with: 128 64 32 16 8 4 2 1 1 1 1 1 1 1 1 1 So, in this case the biggest number is 128+64+32+16+8+4+2+1 which is equal to 255 10. The smallest number is 0 10. Therefore in this case, the range is from 0 to 255. Range using Two s Complement What is the range of numbers which can be represented using 8-bits in two s complement? Since, the first number in two s complement identifies the number as a negative number the highest possible positive number is 01111111 2, which when converted to decimal is 127 10 as shown in the working below. 128 64 32 16 8 4 2 1 0 1 1 1 1 1 1 1 Now, since we have two s complement, we ll need to find the smallest number as well. This can be easily done, by simply converting the positive number to negative so in this case is -127 10. Now the range is from -127 to 126. Notice that for the highest range, one has been subtracted from the value; this is done to compensate for the zero value. Ms. P. Sullivan Page 4 of 7

Left and Right Shift Bit shifting lets us move all of the bits in a binary number type either to the left or to the right for a specified number of times. This will either multiply (left shift) or divide (right shift) the number by 2. If we shift the byte 00110111 2 left once, we get 01101110 2. If we shift 10110011 2, right by three places, we get 00010110 2. Notice in the right-shift example that bits that are shifted out of the byte are lost. This also occurs with left-shifting: if any bits are shifted outside of the "boundaries" of the type in use (eight bits, for a byte), they are lost. Notice that these shifting operations may cause problems with binary numbers that you consider signed (two's complement). Let's try shifting some bytes. If we shift 00000001 (1 10 ) left, we get 00000010 (2 10 ). If we shift that number left, we get 00000100 (4 10 ). If we keep shifting these results to the left, we get the pattern 8, 16, 32 ; each number is double the previous number. So if we want to multiply a number by two, we can shift it left once. This works for any number you might try: 01100101 2 (101 10 ) shifted left is 11001010 2 (202 10 ). However, be aware that if any bits fall outside the range of the type, the resulting byte will no longer be correct. Conversely, shifting a number once to the right, halves the number. But notice that if any bits are shifted outside the range of the type, accuracy is lost. Notice how 00010101 2 (21 10 ), shifted once to the right, gives 00001010 2 (10 10 decimal). The answer should, of course, be 10.5 10, but we are dealing with whole numbers, so the desired 10.5 10 is truncated to 10 10. Why does this work? Well, if we draw our byte diagram, with the values associated with each bit written above... 128 64 32 16 8 4 2 1 0 0 0 1 0 0 0 0...we can see that a 1 in, say, the 16 position that gets shifted left becomes worth 32 instead of 16. Similarly, a bit that is shifted right is worth only half as much. We can multiply (or divide) numbers by powers of two (2, 4, 8, 16, etc) using bit shifting. Obviously, shifting a number left and then shifting the result left again is equivalent to shifting a number left Ms. P. Sullivan Page 5 of 7

by two. The two shift lefts result in multiplying the original number by two and then by two again, with a net result of multiplying by four. Numerical Overflow Numeric overflow happens when the storage allocated for a calculation becomes too small to hold the result of the calculation. So if for example we re using 8 bits (1 byte) to work out binary addition, and the result of the addition is made up of 9 bits, a numeric overflow error occurs. Example 11111111+ 10101010 110101001 So, as you can see from the above addition, the result is made up of 9 bits instead of 8, in that case an error will occur. Ranges When having a limited number of bits for a register, there are three methods which one can use to store a number in the register. These are using sign and magnitude (where the first digit if 0 represents positive and 1 negative) representation, using one s complement and using two s complement. So, assume that we have a register of 8-Bits and we wish to store the number 14 in it. Since in this case the number is positive, it does not pose any difficulty because all we must do is simply convert it to binary and store it (since it is positive, it will be the same in either of the three methods), therefore: 14 10 = 1110 2 Since we re using 8 bits we have to make sure that the number is stored using 8 bits, hence: Ms. P. Sullivan Page 6 of 7

Sign and Magnitude 00001110 One s Complement 00001110 Two s Complement 00001110 Now, if the number we re going to store is -14, some adjustments need to be done. Sign and Magnitude 10001110 Note that the fist digit is 1 because in this case 14 is negative. One s Complement 11110001 In this case we simply applied NOT on the binary value of 14. Two s Complement 11110010 We simply added 1 to the one s complement of 14. *** Ms. P. Sullivan Page 7 of 7