6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10



Similar documents
Computer Science 281 Binary and Hexadecimal Review

Base Conversion written by Cathy Saxton

Section 1.4 Place Value Systems of Numeration in Other Bases

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

NUMBER SYSTEMS. William Stallings

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Binary, Hexadecimal, Octal, and BCD Numbers

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

NUMBER SYSTEMS. 1.1 Introduction

Useful Number Systems

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Lecture 11: Number Systems

Positional Numbering System

CSI 333 Lecture 1 Number Systems

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

The Hexadecimal Number System and Memory Addressing

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 4: Computer Codes

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

Number Systems and Radix Conversion

CS201: Architecture and Assembly Language

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

Lecture 2. Binary and Hexadecimal Numbers

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Binary Numbers. Binary Octal Hexadecimal

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Decimal Notations for Fractions Number and Operations Fractions /4.NF

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

4.3 TABLE 3 TABLE five

Binary Representation

Playing with Numbers

Session 7 Fractions and Decimals

THE BINARY NUMBER SYSTEM

3. Convert a number from one number system to another

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Decimal to Binary Conversion

Click on the links below to jump directly to the relevant section

26 Integers: Multiplication, Division, and Order

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

COMPSCI 210. Binary Fractions. Agenda & Reading

Activity 1: Using base ten blocks to model operations on decimals

Chapter 2. Binary Values and Number Systems

Binary Adders: Half Adders and Full Adders

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

Grade 6 Math Circles. Binary and Beyond

Data Representation. What is a number? Decimal Representation. Interpreting bits to give them meaning. Part 1: Numbers. six seis

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

CPEN Digital Logic Design Binary Systems

Lecture 8: Binary Multiplication & Division

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

JobTestPrep's Numeracy Review Decimals & Percentages

Preliminary Mathematics

6 The Hindu-Arabic System (800 BC)

Number Representation

8 Divisibility and prime numbers

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Pre-Algebra Lecture 6

Count the Dots Binary Numbers

1. The Fly In The Ointment

Number and codes in digital systems

Part 1 Expressions, Equations, and Inequalities: Simplifying and Solving

5.1 Radical Notation and Rational Exponents

1 Description of The Simpletron

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

1.4 Compound Inequalities

What Is Singapore Math?

CS321. Introduction to Numerical Methods

Multiplication and Division with Rational Numbers

So let us begin our quest to find the holy grail of real analysis.

Multiplying and Dividing Signed Numbers. Finding the Product of Two Signed Numbers. (a) (3)( 4) ( 4) ( 4) ( 4) 12 (b) (4)( 5) ( 5) ( 5) ( 5) ( 5) 20

A positive exponent means repeated multiplication. A negative exponent means the opposite of repeated multiplication, which is repeated

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Exponents and Radicals

The BBP Algorithm for Pi

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

Cubes and Cube Roots

47 Numerator Denominator

Linear Programming Notes VII Sensitivity Analysis

CALCULATIONS & STATISTICS

Systems I: Computer Organization and Architecture

Decimals and other fractions

QM0113 BASIC MATHEMATICS I (ADDITION, SUBTRACTION, MULTIPLICATION, AND DIVISION)

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

The string of digits in the binary number system represents the quantity

Section 4.1 Rules of Exponents

Tom wants to find two real numbers, a and b, that have a sum of 10 and have a product of 10. He makes this table.

Basic numerical skills: EQUATIONS AND HOW TO SOLVE THEM. x + 5 = = (2-2) = = 5. x = 7-5. x + 0 = 20.

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Numbering Systems. InThisAppendix...

Kenken For Teachers. Tom Davis June 27, Abstract

Transcription:

Lesson The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base- system. When you perform computations such as + =, or 7 =, you are using the decimal number system. This system, which you likely learned in first or second grade, is ingrained into your subconscious; it s the natural way that you think about numbers. Of course it is not just you: It is the way that everyone thinks and has always thought about numbers and arithmetic. In dealing with the inner workings of a computer, though, you are going to have to learn to think in a different number system, the binary number system, also referred to as the base- system. Before considering why we might want to use a different number system, let s first consider base- number system. More formally, the base- system is a positional system, where the rightmost digit is the ones position (the number of ones), the next digit to the left is the tens position (the number of groups of ), the next digit to the left is the hundreds position (the number of groups of ), and so forth. The base- number system has distinct symbols, or digits (,,,, 8, 9). In decimal notation, we write a number as a string of symbols, where each symbol is one of these ten digits, and to interpret a decimal number, we multiply each digit by the power of associated with that digit s position. For example, consider the decimal number: 9. This number is: 9 = + + + 9 position position position position (i.e., thousands position) (i.e., hundreds position) (i.e., tens position) (i.e., ones position) There is nothing essentially easier about using the base- system. It just seems more intuitive only because it is the only system that you have used extensively, and, again, the fact that it is used extensively is due to the fact that humans have fingers. If humans had six fingers, we would all be using a base- system, and we would all find that system to be the most intuitive and natural. Consider: Computers are built from transistors, and an individual transistor can only be ON or OFF (two options). Similarly, optical storage devices store data in a specific location by controlling whether light is reflected off that location or is not reflected off that location (two options). Likewise, magnetic storage devices store data in a specific location by magnetizing the particles in that location with a specific orientation. We can have the north magnetic pole pointing in one direction, or the opposite direction (two options). Computers can most readily use two symbols, and therefore a base- system, or binary number system, is most appropriate. The base- number system has distinct symbols:,,,,,,, 7, 8 and 9. The base- system has exactly two symbols: and. The base- symbols are termed digits. The base- symbols are termed binary digits, or bits for short. All base- numbers are built as strings of digits (such as 9). All

binary numbers are built as strings of bits (such as ). Just as we would say that the decimal number 89 has five digits, we would say that the binary number is a five-bit number. The point: All data in a computer is represented in binary. The pictures of your last vacation stored on your hard drive it s all bits. The YouTube video of the cat falling off the chair that you saw this morning bits. Your Facebook page bits. The tweet you sent bits. The email from your professor telling you to spend less time on vacation, browsing YouTube, updating your Facebook page and sending tweets that s bits too. Everything is bits. To understand how computers work, you have to speak the language. And the language of computers is the binary number system.. The Binary Number System Just as with decimal notation, we write a binary number as a string of symbols, but now each symbol is a or a. To interpret a binary number, we multiply each digit by the power of associated with that digit s position. For example, consider the binary number. This number is: = + + + = position position position position (i.e., eights position) (i.e., fours position) (i.e., twos position) (i.e., ones position) Since binary numbers can only contain the two symbols and, numbers such as and cannot be binary numbers. We say that all data in a computer is stored in binary that is, as s and s. It is important to keep in mind that values of and are logical values, not the values of a physical quantity, such as a voltage. The actual physical binary values used to store data internally within a computer might be, for instance, volts and volts, or perhaps. volts and. volts or perhaps reflection and no reflection. The two values that are used to physically store data can differ within different portions of the same computer. All that really matters is that there are two different symbols, so we will always refer to them as and. A string of eight bits (such as ) is termed a byte. A collection of four bits (such as ) is smaller than a byte, and is hence termed a nibble. The idea of describing numbers using a positional system, as we have illustrated for base- and base-, can be extended to any base. For example, the base- number is: = + + = position position position

. Converting Between Binary Numbers and Decimal Numbers We humans use the decimal number system, whereas computers use the binary number system. We need to be able to readily shift between the binary and decimal number representations. Converting a Binary Number to a Decimal Number To convert a binary number to a decimal number, we simply write the binary number as a sum of powers of. For example, to convert the binary number to a decimal number, we note that the rightmost position is the ones position and the bit value in this position is a. So, this rightmost bit has the decimal value of. The next position to the left is the twos position, and the bit value in this position is also a. So, this next bit has the decimal value of. The next position to the left is the fours position, and the bit value in this position is a. The leftmost position is the eights position, and the bit value in this position is a. So, this leftmost bit has the decimal value of. Thus: = + + + = 8 + + = Example: Express the binary number as a decimal number. = + + + + + = Some of the most commonly used power of two numbers are: = = = = 8 = = = 7 = 8 8 = 9 = = Given a binary number, you can now convert it to the equivalent decimal number. We will now present two different methods for converting in the other direction: from decimal to binary. The first method is more intuitive. The second method is much more readily adaptable to programming on a computer. Converting a Decimal Number to a Binary Number: Method The first method of converting from a decimal number to a binary number entails expressing the decimal number as a sum of powers of. To convert the decimal number x to binary: Step. Find the highest power of two less than or equal to x. The binary representation will have a one in this position. Denote the value of this highest power of as y.

Step. Now subtract this power of two (y) from the decimal number (x), denoting the result as z: z = x y. Step. If z =, you are done. Otherwise, let x= z and return to Step above. Example: Convert the decimal number 78 to binary. Think to yourself: What is the largest power of that is less than or equal to 78? = < 78 but is it the largest? Let s try = < 78, but is it the largest? Let s try 7 = 8 > 78.. 7. So, the largest power of that is less than 78 is = position:. Thus the binary representation of 78 will have a one in the = = = = 8 = = = Subtracting from our number 78 gives 78 =. Thus, is now the number we are working with. What is the largest power of that is less than or equal to? The answer: = 8. So, the binary representation of 78 will have a one in the = = = = 8 = = = = 8 position: Now, subtracting 8 from our number gives 8 =. Thus, is now the number we are working with. What is the largest power of that is less than or equal to? The answer: =. So, the binary representation of 78 will have a one in the = = = = 8 = = = = position: Now, subtracting from our number gives =. Thus, is now the number we are working with. What is the largest power of that is less than or equal to?

The answer: =. So, the binary representation of 78 will have a one in the = = = = 8 = = = = position: Now, subtracting from our number gives, so we are done. Filling in zeros in all remaining position (i.e., all positions that do not have a ), we have our answer: The decimal number 78 in binary is = = = = 8 = = = or, 78 = Example: Convert the decimal number to binary. 7 = 8 = = = = 8 = = = You should memorize the binary representations of the decimal digits through shown below because you will see them frequently throughout this class. Decimal Number Binary Number Decimal Number Binary Number 8 9 7 You may be wondering about the leading zeros in the table above. For example, the decimal number is represented in the table as the binary number. We could have represented the binary equivalent of as,,, or with any other number of leading zeros. All answers are correct.sometimes, though, you will be given the size of a storage location. When you are given the size of the storage location, include the leading zeros to show all bits in the storage location. For example, if told to represent decimal as an 8-bit binary number, your answer should be. Converting a Decimal Number to a Binary Number: Method The second method of converting a decimal number to a binary number entails repeatedly dividing the decimal number by, keeping track of the remainder at each step. To convert the decimal number x to binary:

Step. Divide x by to obtain a quotient and remainder. The remainder will be or. Step. If the quotient is zero, you are finished: Proceed to Step. Otherwise, go back to Step, assigning x to be the value of the most-recent quotient from Step. Step. The sequence of remainders forms the binary representation of the number. Example: Convert the decimal number to binary using the second method described above. Remainder So, in binary, = Note that the remainder from the very first division of the decimal number by two provides the least significant bit (i.e., the rightmost bit) in the binary representation. The remainder from each division then provides successive bits, from right to left. The remainder of the final division will provide the most significant bit (i.e., the rightmost bit) in the binary representation. We can then add any leading zeros to the result. Example: Convert the decimal number to binary. Remainder So, in binary, = So, now you should be comfortable going back and forth between binary and decimal representations.

. The Hexadecimal Number System We often have to deal with large positive binary numbers. For instance, consider that computers connect to the Internet using a Network Interface Card (NIC). Every NIC in the world is assigned a unique 8-bit identifier as an Ethernet address. The intent is that no two NICs in the world will have the same address. A sample Ethernet address might be: You would probably agree that this long binary string would be cumbersome to transcribe or to read off to a coworker. Even if you have come to love the binary number system, you would still likely agree that these long strings are too much of a good thing. Fortunately, large binary numbers can be made much more compact and hence easier to work with if represented in base-, the so-called hexadecimal number system. You may wonder: Binary numbers would also be more compact if represented in base- why not just convert them to decimal? The answer, as you will soon see, is that converting between binary and hexadecimal is exceedingly easy much easier than converting between binary and decimal. The Hexadecimal Number System The base- hexadecimal number system has digits (,,,,,,, 7, 8, 9, A, B, C, D, E and F). Note that the single hexadecimal symbol A is equivalent to the decimal number, the single symbol B is equivalent to the decimal number, and so forth, with the symbol F being equivalent to the decimal number. Just as with decimal notation or binary notation, we again write a number as a string of symbols, but now each symbol is one of the possible hexadecimal digits ( through F). The first numbers in the decimal, binary, and hexadecimal number systems are listed in the table below. Decimal Number (base ) Binary Number (base ) Hexadecimal Number (base ) 7 7 8 8 9 9 A B C D E F 7

To interpret a hexadecimal number, we multiply each digit by the power of associated with that digit s position. For example, consider the hexadecimal number A9B. Indicating the values associated with the positions of the symbols, this number is illustrated as: A 9 B position position position position Converting a Hexadecimal Number to a Decimal Number To convert a hexadecimal number to a decimal number, write the hexadecimal number as a sum of powers of. For example, considering the hexadecimal number A9B above, we convert this to decimal as: A9B = ( ) A( ) 9( ) B( ) + + + = 9 + () + 9() + () = 8 Example: Express the hexadecimal number CB as a decimal number. CB = + + = 97 Converting a Decimal Number to a Hexadecimal Number The easiest way to convert from decimal to hexadecimal is to use the same division algorithm that you used to convert from decimal to binary, but repeatedly dividing by instead of by. As before, we keep track of the remainders, and the sequence of remainders forms the hexadecimal representation. For example, to convert the decimal number 7 to hexadecimal, we proceed as follows: Remainder 7 A E EA So, the decimal number 7 = EA in hexadecimal Note that with hexadecimal notation, as with binary and decimal notation, we must be careful that the base is understood. When we speak of the number, do we mean the decimal number (in base ), or do we mean the hexadecimal number (which happens to equal in base )? If the base is not clear from the context, it can be made explicit by including the base as a subscript as in: =. Or use the prefix x to indicate that a number is hexadecimal. That is, instead of writing, use the notation x. 8

You may be happy to learn that, as a practical matter, engineers rarely have to convert between decimal and hexadecimal. Converting a Hexadecimal Number to a Binary Number Engineers often have to convert between binary and hexadecimal and that is quite simple to do. We can convert directly from hexadecimal notation to the equivalent binary representation by using the following procedure: Convert each hexadecimal digit to a four digit binary number, independent of the other hexadecimal digits. Concatenate the resulting four-bit binary numbers together. For example, to convert the hexadecimal number DA9 to binary, we first convert each hexadecimal digit to a four-bit string: = D = A = 9 = and then concatenate the results: The resulting binary number is:. Example: Convert the hexadecimal number F to binary. = = F = Thus F = Converting a Binary Number to a Hexadecimal Number Converting from binary to hexadecimal entails reversing the procedure for converting from hexadecimal to binary. Specifically, we can convert directly from binary notation to the equivalent hexadecimal representation by using the following procedure: Starting at the right, collect the bits in groups of Convert each group of bits into the equivalent hexadecimal digit Concatenate the resulting hexadecimal digits For example, to convert to hexadecimal, we collect the bits into groups of starting at the right:, and then we convert each collection of bits into a hexadecimal digit: D A 9 Thus = DA9 Example: Suppose the first byte of a variable is stored at memory location numbered (in binary): 9

We say that this memory location is the address of the variable. What is this variable s address in hexadecimal notation? F F 7 C = FF7C Example: Suppose you are told that an item is at -bit address CAC. What is the value of the fourth bit in this address, counting from the right? Since the last hexadecimal digit is C =. Thus, the fourth bit is a. So, now you should be comfortable going back and forth between binary, decimal and hex representations.