Binary Numbers The Computer Number System

Transcription

1 Binary Numbers The Computer Number System Number systems are simply ways to count things. Ours is the base-0 or radix-0 system. Note that there is no symbol for 0 or for the base of any system. We count,2,3,4,5,6,7,8,9, and then put a 0 in the first column and add a new left column, starting at again. Then we count -9 in the first column again. Each column in our system stands for a power of 0 starting at 0 0. Example: People use the base-0 system because we have 0 fingers! ,357,896 = x one million + 3 x one hundred thousand + 5 x ten thousand + 7 x one thousand + 8 x one hundred + 9 x ten + 6 x one.

3 The Computer Number System All computers use the binary system : Binary number system: Base = 2. Thus there are 2 numbers: 0 and. A single binary number is called a Binary digit, or bit. Computers perform operations on binary number groups called words. Today, most computers use 32- or 64- bit words: Words are subdivided into 8-bit groups called bytes. One-half a byte is sometimes referred to as a nibble (a term not often used anymore). Computer numbers are and 0! A simple electronic switch can represent both binary computer numbers = = 0 3

4 Binary Numeric Representation 4 A 32-bit binary number: We will see ways to make this number more comprehensible below. As mentioned earlier, in the decimal system, each column represents a higher power of ten, starting at the right end with 0 0, e.g.: = x x x x 0 0, and 2002 = 2 x x x x 0 0. Likewise, in the binary number system, which is also positional, each position represents a larger power of two, starting with 2 0 on the right end of the whole number. Consider the binary number = 2 : = x x x x x x x 2 + x 2 0 = 2 8. Or, 23 0 = 0 x x x x x x x 2 + x 2 0 = 0 0 = 0

5 Reading Binary Numbers 5 In a decimal number, a non-0 digit in a column is treated as the multiplier of the power of 0 represented by that column (0 s clearly add no value). We read binary numbers the same way; 0 s count nothing and a in any column means that the power of 2 represented by that column is part of the magnitude of the number. That is:

9 Binary-Hexadecimal Since 2 4 = 6, each hex digit effectively represents the same numeric count as four binary digits. Another way to say this is that one column in a hex number is the same as four columns of a binary number = 0x 95B.7A* *Note: The 0x prefix before a number signifies hexadecimal. 9

12 Some Tricky Conversions Converting hex numbers to binary where leading or trailing zeros result is simple: Just drop the extra zeros! Examples: 0x 7A.F8 = (0)(00).()(000) = 00. 0x 29.3C = (000)(00).(00)(00) = The binary-hex conversion is a little trickier: Starting at the binary point, create group of 4 bits, then convert to hex (Go for fractions, for integers). Add 0 s to either end of the number to complete a group of four if necessary = (000).(00)(0) = 0x 8.3D ( No 0 s needed) = ([0])(00).(00)([00]) = 0x 7A.5C = ([00]0)(0).(00)([000]) = 0x 2E.58 While leading zeroes are only moderately important (you could probably figure out the hex number without completing the group of 4), trailing zeroes are imperative. If a fractional binary number does not have 4 bits in its last group, zeroes must be added to complete the group or the hex number will not be correct! Trailing zeroes are especially important to the value of the fraction. 2

13 More Conversions With Fractions Hex/binary conversion rule: On either side of the hexadecimal point, convert each hex digit to an equivalent 4-bit binary number, and drop leading integral and trailing fractional zeroes. Examples: 0x 79.EA = (0)(00).(0)(00) = x 2D.58 = (000)(0).(00)(000) = Binary/hex conversion rules: () Group binary digits in sets of 4, starting at the binary point (go left for integers, go right for fractions), (2) Add leading zeroes to get a full group of four bits on the left, add trailing zeroes to get a last group on the right, if necessary (The zeroes on the right are very important!), (3) Convert: (4-bit binary number) (hex digit). Examples: = ([0]0)(0).(00)(000) = 0x 67.A = ([00]0)(0).(0)(0[0]) = 0x 2B.7A 3

15 Integer Binary/Decimal Conversions Sadly, we live in a decimal world, so we need to convert from binary to decimal and vice-versa. As we saw in earlier slides, for binary decimal, brute-force is easiest: Ignore zeroes; for any in a column i, add the decimal number represented by 2 to the i th power. Thus: Number to be converted: Power of 2 of columns: Number represented: Thus the decimal number is: = 73. Another example: Number to be converted: Power of 2: Number represented: Thus the decimal number is: =

16 Fractional Binary/Decimal Conversions For numbers right of the binary point, we use the same approach, remembering that the powers of 2 are negative. Number to be converted: 0. 0 Power of 2: Number represented: Thus the decimal number is: = A second example: Number to be converted: Power of 2: Number represented: The decimal number is: =

17 Converting Mixed Binary Numbers Binary numbers with binary point fractions are handled by combining the two techniques shown above: Number to be converted: 0. 0 Power of 2: Number represented: Thus the decimal number is: = Other examples: 0.0 = = = = = = = =

18 Decimal Binary Integer Conversions The easiest way to convert decimal-to-binary integers is the method of successive division. In this method, we simply divide the decimal number by 2: The quotient becomes the new number to divide again. The remainder, which will always be or 0, becomes one bit of the binary number, least significant digit first. The last quotient will always be 0, the last remainder always. Division continues until the quotient is 0 (with a last remainder of ). Thus, converting 26 to binary: 26 2 = 3, remainder = 6, remainder = 3, remainder = =, remainder 2 = 0, remainder

20 Converting Decimal Fractions to Binary Fractions The method of successive multiplication: Decimal to binary fractions. Example Convert 0.25 to binary: 0.25 x 2 = 0.5 ; note 0 to left of binary point. 0.5 x 2 =.0 ; note to left of binary point. There is no part of the decimal fraction left, thus we are done. Read the binary fraction as the numbers to left of binary point in the two results, the remainder from the first multiplication first. Thus, = Decimal-fraction-to-binary-fraction conversion rules: Multiply decimal fraction by 2. Record the number left of the binary point. This will always be a or a 0. Multiply the remaining fraction by 2, repeating above action. Continue until the fraction is eliminated. 20

21 Converting Decimal Binary Fractions (2) Additional examples: 0.375: x 2 = x 2 = x 2 =.0 Thus = : x 2 = x 2 = x 2 =.46 Then, x 2 = (Finite decimal fractions can x 2 =.664 result in repeating binary x 2 =.328 fractions!*) x 2 = x 2 =.32 2 * Thus we must change the last rule on the previous page to read: Continue until the decimal fraction is eliminated or the binary fraction has at least twice as many places as the decimal fraction. This is because each column position in a binary fraction is much more significant than each column position in a decimal fraction.

22 Exercise #3 Convert as directed: 237 to binary: to binary: to binary:

23 Converting Mixed Decimal Numbers Converting mixed decimal numbers means that we must perform two operations. For the integer part of the number, we do the method of successive division. For the decimal part, we do the method of successive multiplication. We recognize that for decimal numbers with a fraction part, we may not be able to convert the number exactly, since we could get a repeating fraction. In that case, we simply do successive multiplication enough times to get the accuracy of the binary fraction that we desire, at least twice the number of decimal places. Note that if the last of the 2x places is a 0, continue until you get a ). 23

25 Doing Binary Math Adding in binary is identical to the operations in our own decimal system. You simply have to remember the Addition table. Thus: Subtraction works the same way but we don t have to worry about subtraction. More on that next lecture. We also don t have to worry about adding more than two numbers. Why? Because a computer can add only two numbers! However, we know that in adding two numbers together, we may actually have to add three numbers there could be a carry from the previous column. 25

26 Assume we are adding two binary numbers together, each with several digits. As in decimal math, we add on a columnar basis. Thus, in any column i, we add the ith digit of number a, the ith digit of number b, and any carry from the (i ) column. Or in any column, the sum is a i plus b i plus c i- ; Sum = a i + b i + c i-. Our new add table is: Adding With A Carry c i- +a i +b i T

27 Adding Examples

28 Adding Answers

29 Homework 29 Anybody in here ever see the movie 50 First Dates? Hopefully, you have listened carefully and perhaps even made a few notes today. Before bedtime tonight, consult your notes (if any), re-read the lecture on-line and make two lists: () things that you thought were important today, and (2) things you did not completely understand. Making list () reinforces your learning; list (2) gives you things to ask about when visiting me during office hours! Remember: those office hours are for YOUR benefit.

30 Hexadecimal-to Decimal Conversion Since hex numbers are used in computer displays, it is useful to convert decimal hex and back. For hex decimal, we use the same brute-force method, as for binary-to-decimal conversion. Consider 3FB7 6 : Number in hex: 3 F B 7 Position as a power of 6: Decimal value of 6 n : F B The decimal number is then 3(4096)+5(256)+(6)+7() = 6,3. 30

32 Integer Decimal-to-Hex Conversion For converting decimal to hexadecimal integers, we use the method of successive division, as for decimal/binary conversions: Convert to hex: We perform successive divisions by =23, remainder 4 (= E) 23 6=, remainder 7 Read in reverse order as before. 6=0, remainder In reverse order, the hexadecimal number is 7E, or = 7E 6. Similarly, converting 65 0 : 65 6=40, remainder (=B) Note that as in binary conversion, 40 6=2, remainder 8 the last quotient will always be =0, remainder 2 However, the last remainder may Thus, 65 0 =28B 6. be anything from to F. 32

34 34 The University of Texas at Dallas Fraction Decimal-to-Hex Conversion For decimal to hexadecimal fraction conversions, we use the method of successive multiplication, as we did for decimal to binary conversions: (we also read for the answer) Convert 0.25 to base 6: 0.25x6=2.0; thus 0.25 = 0x 0.2. Convert 0.335: 0.335x6=5.36;.36x6=5.76;.76x6=2.6, thus x 0.55C. As in the binary case, exact decimal fractions can give hexadecimal repeating fractions. However, since the base 6 is > 0, we do not have to carry out the fraction to so many places in this case the same number of places as the decimal fraction is sufficient. Final example: 0.95 =?.95x6=5.2;.2x6=3.2; thus x 0.F3 (note that 0x 0.F3 = ). Once again, fractional numbers shown as > 9 must be converted to the hex digits A-F (or a-f) to get the correct hexadecimal fraction.

NUMBER SYSTEMS D Number Systems Richard E. Haskell Data inside a computer are represented by binary digits or bits. The logical values of these binary digits are denoted by and, while the corresponding

COMPUTER NUMBER CONVERSIONS Binary to Decimal Conversion Any binary number can be converted to its decimal equivalent simply by summing together the weights of the various positions in the binary number

Number base conversion The human being use decimal number system while computer uses binary number system. Therefore it is necessary to convert decimal number into its binary equivalent while feeding number

23CH_PHCalter_TMSETE_949118 23/2/2007 1:37 PM Page 1 Binary, Hexadecimal, Octal, and BCD Numbers OBJECTIVES When you have completed this chapter, you should be able to: Convert between binary and decimal

Chapter 3 Data Representation in Computers After studying this chapter the student will be able to: *Learn about binary, octal, decimal and hexadecimal number systems *Learn conversions between two different

664 Chapter 23 Binary, Hexadecimal, Octal, and BCD Numbers 23 The Binary Number System Binary Numbers A binary number is a sequence of the digits 0 and, such as 000 The number shown has no fractional part

NUMBER SYSTEMS 1.1 Introduction There are several number systems which we normally use, such as decimal, binary, octal, hexadecimal, etc. Amongst them we are most familiar with the decimal number system.

MT1 Number Systems MT1.1 Introduction A number system is a well defined structured way of representing or expressing numbers as a combination of the elements of a finite set of mathematical symbols (i.e.,

Positional Number Systems A number system consists of an order set of symbols (digits) with relations defined for +,-,*, / The radix (or base) of the number system is the total number of digits allowed

Unit 2: Number Systems, Codes and Logic Functions Introduction A digital computer manipulates discrete elements of data and that these elements are represented in the binary forms. Operands used for calculations

1 Basic Computing Concepts (4) Data Representations The Binary System 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. The

Number Systems The Decimal (Denary) System A good understanding of other number systems depends on a good understanding of the decimal system that you have used for counting and arithmetic since you started

CSCC85 Spring 2006: Tutorial 0 Notes Yani Ioannou January 11 th, 2006 There are 10 types of people in the world, those who understand binary, and those who don t. Contents 1 Number Representations 1 1.1

1 Number Representation and Arithmetic in Various Numeral Systems Computer Organization and Assembly Language Programming 203.8002 Adapted by Yousef Shajrawi, licensed by Huong Nguyen under the Creative

Number System When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. A computer can understand positional number system where there are only

Module 1 www.learnabout-electronics.org Digital Electronics 1.0 Introduction to What you ll learn in Module 1 Section 1.0. Recognise different number systems and their uses. Section 1.1 in Electronics.

Computer Science() Numbering Systems All nations of different civilizations established their own numbering system when they could not comply with the characteristic of their daily lives and activities,

Signed Binary Arithmetic In the real world of mathematics, computers must represent both positive and negative binary numbers. For example, even when dealing with positive arguments, mathematical operations

CHAPTER TWO Numbering Systems Chapter one discussed how computers remember numbers using transistors, tiny devices that act like switches with only two positions, on or off. A single transistor, therefore,

CS Illuminated, 5 th ed. Chapter 2 Review Quiz 1. True or False? A natural number is the number 0 or any number obtained by adding 1 to a natural number. 2. True or False? The category of numbers called

Why Study Data Representation? Computers process and store information in binary format For many aspects of programming and networking, the details of data representation must be understood C Programming

CHAPTER 3 Number System and Codes 3.1 Introduction On hearing the word number, we immediately think of familiar decimal number system with its 10 digits; 0,1, 2,3,4,5,6, 7, 8 and 9. these numbers are called

2 Number Systems 2.1 Foundations of Computer Science Cengage Learning 2.2 Objectives After studying this chapter, the student should be able to: Understand the concept of number systems. Distinguish between

Binary Numbers Bob Brown Information Technology Department Southern Polytechnic State University Positional Number Systems The idea of number is a mathematical abstraction. To use numbers, we must represent

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

Slide 1/40 Learning Objectives In this chapter you will learn about: Non-positional number system Positional number system Decimal number system Binary number system Octal number system Hexadecimal number

Introduction ToNumber Systems Collected by: Zainab Alkadhem Page 1 of 25 Digital systems have such a prominent role in everyday life that we refer to the present technological period as the digital age.

Section.4 Place Value Systems of Numeration in Other Bases Other Bases The Hindu-Arabic system that is used in most of the world today is a positional value system with a base of ten. The simplest reason

NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html

Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

Review Questions: Digital Number Representation 1. What is the significance of the use of the word digit to represent a numerical quantity? 2. Which radices are natural (i.e., they correspond to some aspect

Chapter II Binary Data Representation The atomic unit of data in computer systems is the bit, which is actually an acronym that stands for BInary digit. It can hold only 2 values or states: 0 or 1, true

Number Systems When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. A computer can understand positional number system where there are only

Arithmetic Circuits Addition, Subtraction, & Multiplication The adder is another classic design example which we are obliged look at. Simple decimal arithmetic is something which we rarely give a second

DATA REPRESENTATION All data used by computers is in code form, based on the two digits 0 and 1. This is so, in order to reflect the two-state components of which these digital systems are made. Numbers

Lecture Introduction, Numbers and Number System Contents.. Number Systems (Appendix B)... 2. Example. Converting to Base 0... 2.2. Number Representation... 2.3. Number Conversion... 3. To convert a number

Binary Representation and Computer Arithmetic The decimal system of counting and keeping track of items was first created by Hindu mathematicians in India in A.D. 4. Since it involved the use of fingers

Chapter 2: Number Systems Logic circuits are used to generate and transmit 1s and 0s to compute and convey information. This two-valued number system is called binary. As presented earlier, there are many

Number Representation Number System :: The Basics We are accustomed to using the so-called decimal number system Ten digits ::,,,3,4,5,6,7,8,9 Every digit position has a weight which is a power of Base

Chapter 5 Data Representation Objectives Upon completion of this chapter you will be able to: Describe the binary and hexadecimal number systems, Given a number in one of base 2, 10, or 16, convert that

Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must be able to handle more than just values for real world problems

CHAPTER THREE Binary Math and Signed Representations Representing numbers with bits is one thing. Doing something with them is an entirely different matter. This chapter discusses some of the basic mathematical

Binary Numbers Binary Octal Hexadecimal Binary Numbers COUNTING SYSTEMS UNLIMITED... Since you have been using the 10 different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 all your life, you may wonder how

Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must be able to handle more than just values for real world problems

CHAPTER 1 Discrete Systems Discrete mathematics is the study of techniques, ideas and modes of reasoning that are indispensable in applied disciplines such as computer science or information technology.

Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

Number Systems and Data Representation CS221 Inside today s computers, data is represented as 1 s and 0 s. These 1 s and 0 s might be stored magnetically on a disk, or as a state in a transistor, core,

CS3 Introduction to Numerical Methods Lecture Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506-0633 August 7, 05 Number in