DOC PREVIEW
CSUN COMP 106 - Binary Numbers and Computer Representation of Numerical Data

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

College of Engineering and Computer ScienceComputer Science DepartmentComputer Science 106 Computing in Engineering and ScienceLast update: April 11, 2006 Instructor: Larry CarettoBinary Numbers and Computer Representation of Numerical DataIntroductionMost people have heard that a computer is a binary device, but many students in beginning programming courses are not familiar with the details of binary numbers. Because all data is stored in a computer as a binary representation, that is a series of ones and zeros in the electronic circuits of the computer, it is necessary to understand the structure of binary numbers to understand the limitations of the computer representation of data.These notes first provide a background on binary numbers then discuss how these numbers are used to represent various data types in C++.Binary numbersThe interpretation of binary numbers is a specific application of the general approach to representing numbers in any base. In out usual base ten, we recognize that the number 132 represents 1 times 102 plus 3 times 101 + 2 times 100. We can create a formula for representing this number in base ten and then generalize if to other bases. To start with we write the three digits in our number (the 1, the 3, and the 2 in the number 132) as the symbol, di, for the digit in position i. We number the digits from right to left, starting with the symbol d0 for the rightmost digit, which is 2 in this example of the number 132. We then say that the first digit to the left of d0 is d1, which is 3 in this example. The next digit to the left is d2, which is 1 in our example. We canrepresent a general three-digit number by the symbols d2d1d0. Since this is a base-ten number, we can calculate the value of the number as d2(102) + d1(101) + d0(100). Note that the range of digits for a base ten number is zero to nine.How can we make this more general? We want to represent a number, in any base, with an arbitrary amount of digits in the number. For a base-ten number with N digits, we can write the following equation for the value of the number.)10()10()10()10(001122110121ddddddddNNNNNNHere, we have written the number on the left as a sequence of digits and on the right as the calculation, which gives its value. Note that the subscripts for the digits start with zero for the rightmost digit and range to N-1 for the leftmost digit. This range from zero to N-1 gives us a totalof N digits. We can rewrite the equation above using the usual sigma notation for sums.100121)10(NkkkNNddddd In this equation, we use ten because that is the base of our usual number system. To consider other number systems such a binary (base 2), octal (base 8), or hexadecimal (base 16), we use the same formula, but we replace the factor to ten by the appropriate base, b.Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062100121)(NkkkNNbddddd When want to formally represent the base that we are using for the number, we include it as a subscript following the number. Thus the base-ten number shown above as 132 could be formally written as 13210 to emphasize that this is a decimal (base ten) number.Note that the value of any “digit”, dk in a given numbering system must be less than the base b. We know that decimal (base ten) digits range from zero to 9; similarly octal digits range from 0 to 7 and binary digits range from 0 to 1. Hexadecimal digits range from 0 to f, where we have the following correspondence between hexadecimal digits and base ten numbers: a16 = 1010; b16 = 1110; c16 = 1210; d16 = 1310; e16 = 1410; f16 = 1510. We can write our example number 13210 in the following bases: 13210 = 100001002 = 2048 = 8416.The table below shows the numbers in four bases (decimal, binary, octal and hexadecimal) for numbers from 010 to 2310.Numbers from 010 to 2310 in Four BasesDecimal0 1 2 3 4 5 6 7 8 9 10 11Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011Octal 0 1 2 3 4 5 6 7 10 11 12 13Hex 0 1 2 3 4 5 6 7 8 9 10 aDecimal12 13 14 15 16 17 18 19 20 21 22 23Binary 1100 1101 1110 1111 10000 10001 10010 10011 10100 10101 10110 10111Octal 14 15 16 17 20 21 22 23 24 25 26 27Hex b c d e 10 11 12 13 14 15 16 17You can see from studying this table that there is a convenient relationship between binary numbers and octal or hexadecimal numbers that results in their use for computer notation. The table shows that the binary values for 810 and 1610 are, respectively, 10002 and 100002. Since 108 = 10002, one octal digit is equivalent to three binary digits. You can see this pattern in the table. The last three binary digits in 08 to 78 are repeated for as the last three binary digits for 108 to 178 and for 208 to 278. For numbers between 108 and 178, the repeating pattern of three binary digits is preceded by a 1, the binary representation for the leading octal 1 in this sequence of numbers. Similarly, in numbers between 208 and 278, the repeating pattern of three binary digits is precededby a 10, the binary representation for the leading octal 2 in this sequence of numbers. For binary numbers the only digits we can have are zero and one. Thus our general-base equation is written as follows for binary (b = 2) numbers.100121)2(NkkkNNddddd How large a number can we represent on a computer if we use 16 binary digits? (A binary digit isusually called a bit and eight binary digits or bits are called a byte.) The minimum value of our 16-bit binary number is zero and the maximum occurs when all the bits are one. With N = 16, oursum ranges from k = 0 to k = 15 and we get the following result when all sixteen bits are one.Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062150011415150011415535652222)2(111111111111111111)2(kkkkkkgivesdal lthatsodddddIn any case like this one, where all the binary bits are one, we can add one to the number to obtain the following result.1 12111122020000112111110121100121100121NNNNNkkNNNNNkkNNthatso We can express this result as follows: the maximum value of a binary number with N digits is 2N – 1. If N = 16, we obtain the result shown previously: the maximum number that we can represent is 216 –


View Full Document

CSUN COMP 106 - Binary Numbers and Computer Representation of Numerical Data

Download Binary Numbers and Computer Representation of Numerical Data
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Binary Numbers and Computer Representation of Numerical Data and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Binary Numbers and Computer Representation of Numerical Data 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?