14 Number Representation

14 Number - 14 Computer Representation of Integer and Real Numbers In everyday life numbers are almost exclusively represented using the base 10

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Numbers -1 14 - Computer Representation of Integer and Real Numbers In everyday life, numbers are almost exclusively represented using the base 10 decimal system. This means, for example, that an integer N written as N = a n a n—1 a 1 a 0 (N=231) Corresponds to a short-hand for N = ( a n a n —1 a 1 a 0 ) 10 = a n 10 n + a n —1 10 n —1 + … + a 1 10 1 + a 0 10 0 (N= 2 10 3 + 3 10 1 + 1 10 0 ) In the above case, 10 is called the base (or radix ) of the system. The a ’s are integers between 0 and 9. Rational numbers, numbers with decimal points, make use of the negative powers of the base: N = (0. a 1 a 2 a n-1 a n ) 10 = a 1 10 -1 + a 2 10 -2 + … + a n-1 10 -n+1 + a n 10 -n (N= 0.231=2 10 -1 + 3 10 -2 + 1 10 -3 Computers generally use base 2 which is called the binary system . An integer N is represented as N = ( a n a n —1 a 1 a 0 ) 2 = a n 2 n + a n —1 2 n —1 + … + a 1 2 1 + a 0 2 0 (N=11100111) N = 1*2 7 +1∗ 2 6 + 1 2 5 + 0*2 4 + 0 2 3 + 1 2 2 + 1 2 1 + 1 2 0 The a ’s are only allowed to be 0 and 1. The binary system is quite convenient to computers, since the basic unit of information that they store is an electrical pulse which can be either "on" or "off". A single binary digit (a 0 or a 1) is called a bit . An 8-bit sequence of 0’s and 1’s is usually called a byte . MATLAB makes it easy to convert between base 10 (normal) and binary numbers. >> A=dec2bin(231) A=
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Numbers -2 11100111 You can convert the other way using bin2dec . Experiment with this command to figure out how to use it. Storage of binary numbers The set of all integers is countably infinite. This means that in order to represent all integers, computers would need infinite storage capacity. In reality, computers can store only a finite subset of all integers because each integer is only allowed a certain number bits. The number of bits allocated for any integer is sometimes called a word-length . Using 16-bit integer word-length, the integer N = 231 may be stored as 0 000000011100111. The first of the 16 bits stores the sign of the number (here "positive" is stored as 0), while the remaining 15 bits store the number itself using the binary system representation. Real numbers have decimal points.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 7

14 Number - 14 Computer Representation of Integer and Real Numbers In everyday life numbers are almost exclusively represented using the base 10

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online