Computer Number Systems Supplement

Similar documents
Module 1: Information Representation I -- Number Systems

CS & IT Conversions. Magnitude 10,000 1,

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

Dec Hex Bin ORG ; ZERO. Introduction To Computing

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

Number representations

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

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Memory Addressing, Binary, and Hexadecimal Review

The type of all data used in a C++ program must be specified

Numbers and Representations

CHW 261: Logic Design

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.

Number Systems. Dr. Tarek A. Tutunji Philadelphia University, Jordan

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Chapter 2: Number Systems

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Computer Organization

CC411: Introduction To Microprocessors

Lecture (01) Introduction Number Systems and Conversion (1)

Digital Systems and Binary 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 umbers. Sign/Magnitude otation

Objectives. Connecting with Computer Science 2

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Digital Fundamentals

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

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

Binary, Hexadecimal and Octal number system

Digital Systems and Binary Numbers

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

Objective 1.02 Understand Numbering Systems

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Lecture (02) Operations on numbering systems

T02 Tutorial Slides for Week 2

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Appendix. Numbering Systems. In This Appendix...

CHAPTER 2 Number Systems

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

Number System. Introduction. Decimal Numbers

NUMBER SYSTEMS AND CODES

Appendix. Numbering Systems. In this Appendix

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Number Systems. Both numbers are positive

NUMERIC SYSTEMS USED IN NETWORKING

Binary Codes. Dr. Mudathir A. Fagiri

Chapter 1 Review of Number Systems

1.3 Systems of numeration: To represent quantities in the different systems of numeration, specific symbols are used, which are also called ciphers.

THE LOGIC OF COMPOUND STATEMENTS

Chapter 2 Exercises and Answers

Level ISA3: Information Representation

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

Bits, Words, and Integers

The type of all data used in a C (or C++) program must be specified

Discussion. Why do we use Base 10?

Data Representation 1

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Topic Notes: Bits and Bytes and Numbers

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

Mastering Binary Math

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

DIGITAL SYSTEM DESIGN

Octal and Hexadecimal Integers

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

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 within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Teaching KS3 Computing. Session 3 Theory: More on binary and representing text Practical: Introducing IF

Final Labs and Tutors

CHAPTER 2 (b) : AND CODES

REPRESENTING INFORMATION:

Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

= Chapter 1. The Binary Number System. 1.1 Why Binary?

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

BSC & BIT Numbering Systems. ITU Lecture 3b

Conversion Between Number Bases

CMPE223/CMSE222 Digital Logic Design. Positional representation

The. Binary. Number System

What Is It? Instruction Register Address Register Data Register

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

MC1601 Computer Organization

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Topic Notes: Bits and Bytes and Numbers

World Inside a Computer is Binary

Number systems and binary

Chapter 2. Data Representation in Computer Systems

umber Systems bit nibble byte word binary decimal

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

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Variables and Data Representation

Digital Logic Lecture 2 Number Systems

LOGIC DESIGN. Dr. Mahmoud Abo_elfetouh

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Logic, Words, and Integers

Transcription:

Computer Number Systems Supplement Dr. Ken Hoganson, All Rights Reserved. SUPPLEMENT CONTENTS S.1 Decimal System: Powers-of-the-Base 2 S.2 Converting to Binary: Division/Remainder Algorithm. 3 S.3 Binary Addition. 4 S.4 Bits, Bytes, and Words. 5 S.5 Hexadecimal Number System.. 6 S.6 Negative Numbers 8

Computer Number Systems, Dr. Ken Hoganson, 2 S.1 Decimal System: Powers-of-the-Base The decimal number system is based on powers of the base 10. The place value of each digit is a power of ten. We are so comfortable with this system, that we don t even think about the underlying mechanism. For instance, the number 1259 uses digits in place values that are based on powers of the base (base 10): the 9 is in the 10 0 the 5 is in the 10 1 the 2 is in the 10 2 the 1 is in the 10 3 column - 1s column column - 10s column column - 100s column column - 1000s column 1259 is 9 X 1 = 9 + 5 X 10 = 50 + 2 X 100 = 200 + 1 X 1000 = 1000 ----- 1259 The computer s hardware logic is implemented with transistors, which can work like switches, turning electricity on or off. If we consider on to be a 1, and off to be 0, then internal computer logic can be represented using the Binary number system. The Binary number system uses the same mechanism as the decimal system outlined above, but the base is different - base 2 (binary) rather than base 10 (decimal). The place values for binary are based on powers of the base 2: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 128 64 32 16 8 4 2 1 So, the binary number 10110011 can be converted to decimal so we can understand it, by using the powers-of-the-base mechanism: 1 0 1 1 0 0 1 1 = 1 X 1 = 1 1 X 2 = 2 0 X 4 = 0 0 X 8 = 0 1 X 16 = 16 1 X 32 = 32 0 X 64 = 0 1 X 128 = 128 v ------------------------------- SUM = 179 in decimal

Computer Number Systems, Dr. Ken Hoganson, 3 S.2 Division/Remainder Algorithm: Converting to Binary Section C.1 explained how the decimal system works, and how the binary system uses the same mechanism. In the process, a way to convert a binary number to a decimal number was discovered, by using the powers-of-the-base system. To convert in the other direction, from decimal to binary, requires a different method called the division/remainder method. The idea is to repeatedly divide the decimal number to be converted, by the base to be converted into (base 2). The remainders that result are the binary digits. Example: convert 155 to binary: Start from the bottom and work up. Stop 2)1 Q = 0, R = 1 2)2 Q = 1, R = 0 2)4 Q = 2, R = 0 2)9 Q = 4, R = 1 2)19 Q = 9, R = 1 2)38 Q = 19, R = 0 2)77 Q = 38, R = 1 Start: 2 )155 Q = 77, R = 1 Answer is 10011011. Be careful to read the digits in the correct order. Check the answer with the powers-of-the-base system: 1 X 1 = 1 1 X 2 = 2 1 X 8 = 8 1 X 16 = 16 1 X 128 = 128 ----- 155

Computer Number Systems, Dr. Ken Hoganson, 4 S.3: Addition in Binary Just as in decimal, binary numbers can be added together. Because the base is different, the carry over to the next column is different. In decimal, when a column adds up to more than 9, a carry is added to the column to the left (the next higher place value). Since the base is 2 in binary with digits of 0 and 1, when a sum evaluates to more than 1, a carry must be added to the column to the left. Examples: 11 1 + 1 10 11 101 + 1 110 111 111 10110 + 1101 100011

Computer Number Systems, Dr. Ken Hoganson, 5 S.4: Bits, Bytes, and Words Bits are organized into groups inside the computer system. The most common grouping is to place eight bits in a byte. A byte just looks like a string of eight zeros and ones: 10101110. The range of possible binary values that a byte can hold is from 00000000 to 11111111 There are 256 possible combinations of zeros and ones arranged in any order in a byte. The number of possible combinations is based on a power of the base: 2 #of bits = the number of combinations Examples: Number of bits Number of combinations 1 2 1 = 2 combinations (0 and 1) 2 2 2 = 4 combinations, (00, 01, 10, 11) 6 2 6 = 64 10 2 10 = 1024 A byte can hold a small number, or a single character. Characters are all the letters of the alphabet in upper and lower case, punctuation symbols, the digits 0-9, and can include other special symbols. Bytes can be grouped together to form words. A word is simply one or more bytes, but is has a meaning in terms of the computer s power. A computer with a word size of a single byte, can work with and manipulate data eight bits at a time (a rough approximation). A sixteen-bit computer (word size of two bytes) is more powerful, because it can access and manipulate 16 bits at a time rather than 8. Typical word sizes for our common personal computers are 32-bit (4 bytes) and 64-bit (8 bytes). Computer systems include large quantities of bytes billions and trillions or bytes are becoming common. In dealing with these large numbers, a shorthand way to refer to large numbers of bytes has developed. Shorthand Term Roughly Power of 2 Actual K Kilobyte Thousand 2 10 1024 M or Meg Megabyte Million 2 20 1,048,576 G or Gig Gigabtye Billion 2 30 1,073,741,824 T Terabyte Trillion 2 40 1,099,511,627,776

Computer Number Systems, Dr. Ken Hoganson, 6 S.5: Hexadecimal Number System Another number system used in computing is the hexadecimal system. Hexadecimal is base-16 number system, that is, just as decimal has a base of 10 (10 digits, 0-9), and binary is base 2 (2 digits, 0-1), hexadecimal is base-16 (16 digits, 0-15). But representing the values from 10-15 is problematic a single numeral is needed to represent those values. The first six letters of the alphabet are used for those integers: 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Note that just as decimal includes digits for 0-9, and the 10 is two digits, with the 1 in the tens column, hexadecimal includes digits for 0-15, and sixteen is represented with a 1 in the sixteen s column. In hexadecimal, 10 is worth sixteen in decimal. The same place value mechanism used in decimal and binary applies to hexadecimal as well, place values are based on powers of the base, in this case, base sixteen. For example, 1B52 in hexadecimal can be converted to our more familiar decimal system: the 2 is in the 16 0 column - 1s column the 5 is in the 16 1 column - 16s column the B (11) is in the 16 2 column - 256s column the 1 is in the 16 3 column - 4096s column 1B52 16 is 2 X 1 = 2 + 5 X 16 = 80 + 11 X 256 = 2816 + 1 X 4096 = 4096 ----- 6994 10 Subscripts are often used to indicate the base of the number, which is not always apparent just from looking at the digits. Hexadecimal turns out to be a useful number system for working with binary digital computers because of the relationship between base-16 and base-2. Sixteen is a convenient power of the base-2: 2 4 = 16. So four binary (base-2) digits that span values from 0000 1111 (15) cover the same set of value as one hexadecimal digit (0-15). Thus, a group of four bits can be conveniently represented with a single hexadecimal digit as follows:

Computer Number Systems, Dr. Ken Hoganson, 7 Base-2, Binary Base-16, Hexadecimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F So if a group of four binary digits can be represented with a single hexadecimal digit, then an 8- bit byte can be represented with two hexadecimal digits: Binary Hexadecimal 0001 0001 11 1000 1000 88 1100 1011 CB 1111 0111 F7 Note that it is far more convenient to talk about digital binary values in hexadecimal than it is in binary. For instance, a sixteen bit binary value: 1100100100100101 can be easily shared or recorded as C925. Converting from binary to hexadecimal (hex), and hex to binary is easily down without a formal conversion process, simply by grouping bits into groups of four bits, and translating that binary value to its equivalent hex digit. At first the student may need to use decimal as an intermediary: 1001 9 9 1101 13 D F 15 1111 7 7 0111 Converting multi-digit values: Binary Hex 01101001 0110 1001 6,9 69 10110001 1011 0001 11,1 B1 Hex Binary A8 10,8 1010 1000 10101000 3F 3,15 0011 1111 00111111

Computer Number Systems, Dr. Ken Hoganson, 8 Section S.6: Negative Numbers So far we have worked with unsigned binary values, but number systems need to be able to represent both positive and negative numbers. For the purposes of this discussion, we will limit ourselves to values with 8 binary bits. In eight bits, a range of values can be represented. There are 256 possible combinations of 0s and 1s with eight bits, ranging from 00000000 up to 11111111. An examination of the range of values follows: Binary Hex Decimal 00000000 00 0 00000001 01 1 00000010 02 2 00000011 03 3 11111100 FC 252 11111101 FD 253 11111110 FE 254 11111111 FF 255 There are 256 possible combinations allowing values from 0 to 255. The number of combinations is also based on Powers-of-the-Base: 2 8 = 256. To represent negative numbers (in eight bits) some of the available values must be dedicated to represent negative numbers, and some to positive value.

Computer Number Systems, Dr. Ken Hoganson, 9 Sign-Magnitude The most obvious way to represent negative numbers is to use one of the digits to represent a sign bit, which indicates whether the number is to be positive or negative. The convention is to use the left-most bit for the sign bit, with zero meaning a positive number and 1 meaning a negative number. The available combinations of 0s and 1s now have a different meaning: Binary Hex Decimal S 00000000 00 +0 00000001 01 +1 00000010 02 +2 00000011 03 +3 01111110 7E +126 01111111 7F +127 10000000 80-0 negative zero? 10000001 81-1 10000010 82-2 11111100 FC -124 11111101 FD -125 11111110 FE -126 11111111 FF -127 Two problems with sign-magnitude representation are apparent from the above table of values: 1. There are two representations for zero, both a positive zero and a negative zero. Not only is this incorrect, but the two representations for zero waste a combination that could otherwise be used to represent some other value. 2. Another problem with sign-magnitude representation is revealed only when attempting basic mathematics. For instance adding a positive and negative number should work correctly: 7 00000111 + -5 10000101 -------- ------------ 2 10001010 = -12! The problem with working with positive and negative numbers can be fixed for sign-magnitude. Addition circuits can be designed to work correctly for adding numbers of each combination of signs of values: + + - - + - + - Four different addition circuits can be designed inside the CPU to handle each case, but this requires four times the circuitry and transistors to implement, clearly not efficient. And special cases need to be created for the other operations, not just addition. And each case must also correctly recognize the two representations for zero.

Computer Number Systems, Dr. Ken Hoganson, 10 Two s Complement A better approach is a method called Two s-complement. It is more complicated and nonintuitive, and only the unsolvable problems of the sign-magnitude representation drive the use of two s-complement. But two s-complement does indeed work correctly and avoids the need for separate circuits to implement math with combinations of positive and negative numbers. In Two s Complement, A single bit is used to represent the sign of the number, and the left-most bit is still used for the sign. But the meaning of the combinations of bits is different than signmagnitude for the negative numbers. The negative numbers count down from -128 in the progression of bit combinations: Binary Hex Decimal S 00000000 00 +0 00000001 01 +1 00000010 02 +2 00000011 03 +3 01111110 7E +126 01111111 7F +127 - - - - - - - - - - - - 10000000 80-128 10000001 81-127 10000010 82-126 11111100 FC -4 11111101 FD -3 11111110 FE -2 11111111 FF -1 It is now difficult to read a negative number, as the meaning of the bits are reversed (complemented). Note that there is now only one representation for zero, and the extra combination allows an extra value to be represented: -128. So the combinations with the zero as the sign bit range from 0 up to 127, and the combinations with the one as the sign bit range from - 128 down to -1. Fortunately, there is a simple way to translate or understand the meanings of the negative values, and its how this representation got its name. To convert a positive value to its negative representation in two s complement, a two-step process is used: Start with the binary positive representation: Complement (reverse) all the bits (one s complement) Add one.

Computer Number Systems, Dr. Ken Hoganson, 11 Example: find the two s complement representation of -3: A positive 3 in 8-bits is: 00000011 Complementing the bits: 11111100 Add one +00000001 -------------- 11111101 = -3 This is the same value for negative 3 shown in the previous table of values. The same two s-complement steps can also be used to translate or convert a negative value: A negative 3 in 8-bits is: 11111101 Complementing the bits: 00000010 Add one +00000001 -------------- 00000011 = +3 So a negative two s complement value can be read by finding its positive value equivalent for the magnitude of the number, and remembering that it s the negative of that value. Two s-complement and Math: Two s-complement does indeed solve the problem with working with combinations of signs: 7 00000111 = +7 + -5 11111011 = -5 -------- ------------ 2 1 00000010 = +2! Notice that the carry from the addition of ones to the next place value carrys over beyond the eight bits, and inside the computer, this result is noted but the bit is discarded [Somewhat amusingly described as thrown into the bit bucket, though there is no actual bit-bucket inside the machine]. Another example: -7 11111001 = -7 + -5 11111011 = -5 -------- ------------ -12 1 11110100 = -12!

Computer Number Systems, Dr. Ken Hoganson, 12 Supplement Exercises: Work out the following problems on paper (show your work). Convert from binary to decimal: 1. 1001 2. 0011 3. 10011000 4. 01001101 Work the following problems, converting decimal to binary (show all work) 5. 7 6. 15 7. 113 8. 238 Work the following programs, representing the following decimal numbers in two s complement binary in eight bits. 9. 12 10. 100 11. -30 12. -97