FACTOID # 137: Sick people is Switzerland stay in hospital for longer than the people of any other nation - almost 10 days, on average. Switzerland also has the world's highest number of hospital beds per capita.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Computer numbering formats

The term computer numbering formats refers to the schemes implemented in digital computer and calculator hardware and software to represent numbers. A common mistake made by non-specialist computer users is a certain misplaced faith in the infallibility of numerical computations. ... For other uses, see Calculator (disambiguation). ... A number is an abstract entity used originally to describe quantity. ... In telecommunication, the term user has the following meanings: 1. ... This article needs to be cleaned up to conform to a higher standard of quality. ...


For example, if one multiplies: 3 times frac13 one might perhaps expect to get a result of exactly 1, which is the correct answer when applying an exact rational number or algebraic model. In practice, however, the result on a digital computer or calculator may prove to be something such as 0.9999999999999999 (as one might find when doing the calculation on paper) or, in certain cases, perhaps 0.99999999923475. In mathematics, a rational number is a number which can be expressed as a ratio of two integers. ... This article is about the branch of mathematics. ...


The latter result seems to indicate a bug, and it is a surprise to many that this is the way it is designed to work if you use a binary floating-point approximation. Decimal floating-point, computer algebra systems, and certain bignum systems would give either the answer of 1 or 0.9999999999999999... A computer bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from working as intended, or produces an incorrect result. ... A floating-point number is a digital representation for a number in a certain subset of the rational numbers, and is often used to approximate an arbitrary real number on a computer. ... The decimal (base ten or occasionally denary) numeral system has ten as its base. ... A computer algebra system (CAS) is a software program that facilitates symbolic mathematics. ... A bignum package in a computer or program allows internal representation of very large integers, rational numbers, decimal numbers, or floating-point numbers (limitted only by available memory), and provides a set of arithmetic operations on such numbers. ...

Contents

Bits, bytes, nibbles, and unsigned integers

Bits

The concept of a bit can be understood as a value of either 1 or 0, on or off, yes or no, or encoded by a switch or toggle of some kind. A single bit must represent one of two states: This article is about the unit of information. ... For other senses of the word code, see code (disambiguation). ... A toggle switch is a generic class of electric switch that uses a mechanical lever, handle or rocking mechanism to actuate it. ... In information processing, a state is the complete set of properties (for example, its energy level, etc. ...

 one-digit binary value: decimal value: ----------------------- -------------- 0 0 1 1 two distinct values 


While a single bit, on its own, is able to represent only two values, a string of two bits together are able to represent increasingly more unique values: In computer programming and formal language theory, (and other branches of mathematics), a string is an ordered sequence of symbols. ...

 two-digit binary value: decimal value: ----------------------- -------------- 00 0 01 1 10 2 11 3 four distinct values 


A series of three binary digits can likewise designate twice as many distinct values as the two-bit string. Look up binary in Wiktionary, the free dictionary. ... In mathematics and computer science, a numerical digit is a symbol, e. ...

 three-digit binary value: decimal value: ------------------------- -------------- 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7 eight distinct values 


As the number of bits within a sequence goes up, the number of possible 0 and 1 combinations increases exponentially. The examples above show that a single bit allows only two value-combinations, while two bits combined can make four separate values; three bits yield eight possibilities, and the amount of possible combinations doubles with each binary digit added: Exponentiation is a mathematical operation, written an, involving two numbers, the base a and the exponent n. ...

 bits in series (b): number of possible values (N): ------------------------- ------------------------------ 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 ... 2b = N 

Bytes

A byte is a sequence of eight bits or binary digits that can represent one of 256 possible values. Modern computers process information in 8-bit units, or some other multiple thereof (such as 16, 32, or 64 bits) at a time. A group of 8 bits is now widely used as a fundamental unit, and has been given the name of octet. A computer's smallest addressable memory unit (a byte) is typically an octet, so the word byte is now generally understood to mean an octet. In computer science a byte (pronounced bite) is a unit of measurement of information storage, most often consisting of eight bits. ... The ASCII codes for the word Wikipedia represented in binary, the numeral system most commonly used for encoding computer information. ... In mathematics, a power of two is any of the nonnegative integer powers of the number two; in other words, two times itself a certain number of times. ... In computer technology and networking, an octet is a group of 8 bits. ... In computer science a byte (pronounced bite) is a unit of measurement of information storage, most often consisting of eight bits. ...


Nibbles

A unit of four bits, or half an octet, is often called a nibble (or nybble). It can encode 16 different values, such as the numbers 0 to 15. Any arbitrary sequence of bits could be used in principle, but in practice the most common scheme is: A nibble (or less commonly but more accurately, nybble) is the computing term for a four-bit aggregation, or half an octet (an octet being an 8-bit byte). ... A number is an abstract idea used in counting and measuring. ...

 0000 = decimal 00 1000 = decimal 08 0001 = decimal 01 1001 = decimal 09 0010 = decimal 02 1010 = decimal 10 0011 = decimal 03 1011 = decimal 11 0100 = decimal 04 1100 = decimal 12 0101 = decimal 05 1101 = decimal 13 0110 = decimal 06 1110 = decimal 14 0111 = decimal 07 1111 = decimal 15 

This order (rather than gray code) is used because it is a positional notation, like the decimal notation that humans are more used to. For example, given the decimal number: The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one digit. ... A positional notation or place-value notation system is a numeral system in which each position is related to the next by a constant multiplier, a common ratio, called the base or radix of that numeral system. ... The decimal (base ten or occasionally denary) numeral system has ten as its base. ...

7531

is commonly interpreted as:

(7 × 1000) + (5 × 100) + (3 × 10) + (1 × 1)

or, using powers-of-10 notation:

(7 × 103) + (5 × 102) + (3 × 101) + (1 × 100)

(Note that any non-zero number to the zero power is 1.) Exponentiation is a mathematical operation, written an, involving two numbers, the base a and the exponent n. ...


Each digit in the number represents a value from 0 to 9 (hence ten different possible values) which is why this is called a decimal or base-10 number. Each digit also has a weight of a power of ten associated with its position. In mathematics and computer science, a numerical digit is a symbol, e. ...


Similarly, in the binary number encoding scheme mentioned above, the (decimal) value 13 is encoded as: The binary numeral system, or base-2 number system, is a numeral system that represents numeric values using two symbols, usually 0 and 1. ...

 1101 

Each bit can only have a value of 1 or 0 (hence only two possible values) so this is a binary, or base-2 number. Accordingly, the positional weighting is as follows:

 1101 = (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20) = (1 × 8) + (1 × 4) + (0 × 2) + (1 × 1) = 13 decimal 

Notice the values of powers of 2 used here: 1, 2, 4, 8. Experienced computer programmers generally know the powers of 2 up to the 16th power because they use them often:

 20 = 1 28  = 256 21 = 2 29  = 512 22 = 4 210 = 1,024 23 = 8 211 = 2,048 24 = 16 212 = 4,096 25 = 32 213 = 8,192 26 = 64 214 = 16,384 27 = 128 215 = 32,768   216 = 65,536 

Sometimes, in this context (and unlike the SI International System of Units) the value 210 = 1,024 is referred to as Kilo, or simply K (sometimes referred to as Kibibyte), so any higher powers of 2 are often conveniently referred to as multiples of that value: Look up si, Si, SI in Wiktionary, the free dictionary. ... According to the International Electrotechnical Commission a kibibyte (a contraction of kilo binary byte) is a unit of information or computer storage. ...

 211 = 2 K = 2,048 214 = 16 K = 16,384 212 = 4 K = 4,096 215 = 32 K = 32,768 213 = 8 K = 8,192 216 = 64 K = 65,536 

Similarly, the value 220 = 1,024 × 1,024 = 1,048,576 is referred to as a Meg, or simply M (sometimes referred to as Mebibyte): The three-letter acronym MIB may refer to any of several concepts: Management information base, a computing information repository used (for example) by SNMP In marbles, any marble, but esp. ...

 221 = 2 M 222 = 4 M 

and the value 230 is referred to as a Gig, or simply G (sometimes referred to as Gibibyte). The term gib may refer to: a castrated male cat or ferret an abbreviation for gibibyte (GiB) or gibibit (Gib) an abbreviation for Gibraltar an abbreviation for Gib Board, itself an abbreviation of Gibraltar Board, all Winston Wallboards[1] tradenames for drywall (plasterboard). ...


However, in December 1998 the International Electrotechnical Commission produced new units for these power-of-two values, in order to bring prefixes such as kilo- and mega- back to their SI definitions. (See Binary prefix.) The International Electrotechnical Commission (IEC) is an international standards organization dealing with electrical, electronic and related technologies. ... // In computing, binary prefixes can be used to quantify large numbers where powers of two are more useful than powers of ten (such as computer memory sizes). ...


(There is another subtlety in this discussion. If we use 16 bits, we can have 65,536 different values, but the values are from 0 to 65,535. Humans start counting at one, machines start counting from zero, since it is easier to program them this way. This detail often confuses.)


The binary scheme just outlined defines a simple way to count with bits, but it has a few restrictions:

  • You can only perform simple arithmetic within the bounds of the number of bits that you have. That is, if you are working with 16 bits at a time, you can't perform arithmetic that gives a result of 65,536 or more.
  • There is no way to represent fractions with this scheme. You can only work with non-fractional (integer) quantities.
  • There is no way to represent negative numbers with this scheme. All the numbers are zero or positive (unsigned).

Despite these limitations, such unsigned integer numbers are very useful in computers for counting things one-by-one. They are very simple for the computer to manipulate. Arithmetic tables for children, Lausanne, 1835 Arithmetic or arithmetics (from the Greek word αριθμός = number) is the oldest and most elementary branch of mathematics, used by almost everyone, for tasks ranging from simple daily counting to advanced science and business calculations. ... For other meanings of the word fraction, see fraction (disambiguation) A cake with one quarter removed. ... The integers are commonly denoted by the above symbol. ... A negative number is a number that is less than zero, such as −3. ... Signedness is a property of an integer number used by a compiler to indicate if variables of a numeric type are capable of storing both positive and negative numbers, or just positive. ...


Why binary?

  • The logic that computers use is Boolean logic which is a two-valued logic, and thus the two states of a binary system can relate directly to two states in a logical system.
  • It was easier to make hardware which can distinguish between two values than multiple values. Imagine a light switch as compared to a clock.
  • Binary is slightly more efficient than decimal. Many early computers used decimal (usually in binary-coded decimal representation). This seemingly-natural approach was eventually largely abandoned due to the increase in processing circuitry (as compared to binary) which reduced reliability.
  • Other bases have been tried. A few experimental computers have been built with ternary (base 3) representation, as it was thought it might be more efficient than binary.[1]

Boolean logic is a complete system for logical operations. ... In computing and electronic systems, Binary-coded decimal (BCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence. ... Ternary or trinary is the base-3 numeral system. ...

Octal and hex number display

See also Base 64. In computing, base64 is a data encoding scheme whereby binary-encoded data is converted to printable ASCII characters. ...


Octal and hex are a convenient way to represent binary numbers, as used by computers. Computer mechanics often need to write out binary quantities, but in practice writing out a binary number such as 1001001101010001 is tedious, and prone to errors. Therefore, binary quantities are written in a base-8 ("octal") or, much more commonly, a base-16 ("hexadecimal" or "hex") number format.


In the decimal system, there are 10 digits (0 through 9) which combine to form numbers as follows:

 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... 

In an octal system, there are only 8 digits (0 through 7):

 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 ... 

That is, an octal "10" is the same as a decimal "8", an octal "20" is a decimal 16, and so on.


In a hex system, there are 16 digits (0 through 9 followed, by convention, with A through F): For other uses of A, see A (disambiguation). ... Look up F, f in Wiktionary, the free dictionary. ...

 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 ... 

That is, a hex "10" is the same as a decimal "16" and a hex "20" is the same as a decimal "32".


Converting between bases

Each of these number systems are positional systems, but while decimal weights are powers of 10, the octal weights are powers of 8 and the hex weights are powers of 16. To convert from hex or octal to decimal, for each digit one multiplies the value of the digit by the value of its position and then adds the results. For example:

 octal 756 = (7 × 82) + (5 × 81) + (6 × 80) = (7 × 64) + (5 × 8) + (6 × 1) = 448 + 40 + 6 = decimal 494 
 hex 3b2 = (3 × 162) + (11 × 161) + (2 × 160) = (3 × 256) + (11 × 16) + (2 × 1) = 768 + 176 + 2 = decimal 946 

Thus, an octal digit has a perfect correspondence to a 3-bit binary value number:

 000 = octal 0 001 = octal 1 010 = octal 2 011 = octal 3 100 = octal 4 101 = octal 5 110 = octal 6 111 = octal 7 

Similarly, a hex digit has a perfect correspondence to a 4-bit binary number:

 0000 = hex 0 1000 = hex 8 0001 = hex 1 1001 = hex 9 0010 = hex 2 1010 = hex a 0011 = hex 3 1011 = hex b 0100 = hex 4 1100 = hex c 0101 = hex 5 1101 = hex d 0110 = hex 6 1110 = hex e 0111 = hex 7 1111 = hex f 

So it is easy to convert a long binary number, such as 1001001101010001, to octal:

 001 001 001 101 010 001 binary = 1 1 1 5 2 1 111521 octal 

and easier to convert that number to hex:

 1001 0011 0101 0001 binary = 9 3 5 1 9351 hexadecimal 

but it is harder to convert it to decimal (37713).


Conversion of numbers from hex or octal to decimal can also be done by using the following pattern.


(d1 * base + d2) * base + dn........


Where the first digit in the number is multiplied by the numbers base and added to the second digit. To convert numbers with three digits or more the pattern is just continued.


Examples of this are shown below.


hex A1


d1=A(or decimal 10) d2=1 base=16


d1 * base + d2


10 * 16 + 1= decimal 161


hex 129


d1=1 d2=2 d3=9 base=16


(d1 * base + d2) * base + d3= (1 * 16 + 2) * 16 + 9= decimal 297


The same method can be applied to conversion of octal and binary numbers:


binary 1011


d1=1 d2=0 d3=1 d4=1 base=2


((d1 * base + d2) * base + d3) * base + d4=


((1 * 2 + 0) * 2 + 1) * 2 + 1= decimal 11


octal 1232


d1=1 d2=2 d3=3 d4=2 base=8


(((d1 * base) + d2) * base + d3) * base + d4=


((1 * 8 + 2) * 8 + 3) * 8 + 2= decimal 666


Representing signed integers in binary

Main article: Signed number representations

Binary numbers have no inherent way to representing negative numbers in a computer. In order to create these "signed integers" a few different systems have been developed. In each, a special bit is set aside as the "sign bit", which is usually the leftmost (most significant) bit. If the sign bit is 1 the number is negative; if 0, positive. In mathematics, negative numbers in any base are represented in the usual way, by prefixing them with a − sign. ...


Sign-magnitude

Sign-magnitude representation is possibly the simplest way to represent a signed number. The representation consists of one sign bit and other bits denoting the magnitude, or absolute value, of the number. For example, using 4 bits: In computer science the sign bit is the bit in a computer numbering format which indicates the sign of the number. ... In mathematics, the absolute value (or modulus[1]) of a real number is its numerical value without regard to its sign. ...

 0101 = +5 1101 = -5 

Ones' complement

In ones' complement, the inverse of a number is formed by complementing each bit — that is, performing a bitwise NOT operation. For example:

 0101 = +5 1010 = -5 

A side effect of both this and the previous system, one of the reasons these systems are not often used for computing, is that there are two representations for zero. In ones' complement:

 0000 = +0 1111 = -0 

In sign-magnitude:

 0000 = +0 1000 = -0 

Two's complement

Two's complement is the most widely used system in modern computing. To form the two's complement, take the bitwise NOT of the number and add 1. For example: The twos complement of a binary number is the value obtained by subtracting the number from a large power of two (specifically, from 2N for an N-bit twos complement). ...

 0101 = +5 1011 = -5 

Thus:

 0000 = decimal 0 1000 = decimal -8 0001 = decimal 1 1001 = decimal -7 0010 = decimal 2 1010 = decimal -6 0011 = decimal 3 1011 = decimal -5 0100 = decimal 4 1100 = decimal -4 0101 = decimal 5 1101 = decimal -3 0110 = decimal 6 1110 = decimal -2 0111 = decimal 7 1111 = decimal -1 

Using this system, 16 bits will encode numbers from −32,768 to 32,767, while 32 bits will encode −2,147,483,648 to 2,147,483,647.


The great advantage of the two's complement system is that most operations are not dependent on the sign of the operands and furthermore are identical to operations on unsigned binary integers.


For instance, 5 + (-5) would be performed like this:

 0101 +1011 10000 

However, seeing as we have taken the numbers as 4 bits long, the leading 1 is discarded and we have the expected result of 0.


The fact that most operations work no matter the sign of the operands can be explained through the duplicity of numbers modulo 2n; e.g. 15 ≡ -1 (mod 16). Computers generally use a fixed number of bits for binary numbers and thus such a system is ideal. Essentially the only difference between two's complement numbers and unsigned numbers is how they are displayed and compared.


One quirk of two's complement is that the lowest encodable number (e.g. -32768 for 16 bit numbers) appears to be its own negative. However, this rarely causes problems.


As a number composed entirely of 1s (such as 11111111) equates to -1 in two's complement notation, many programming languages use -1 for true and 0 for false.


Representing fractions in binary

Fixed-point numbers

Fixed-point formats are often used in business calculations (such as with spreadsheets or COBOL), where floating-point with insufficient precision is unacceptable when dealing with money. It is helpful to study it to see how fractions can be stored in binary. In mathematics, a fixed point of a function f is an argument x such that f(x) = x; see fixed point (mathematics). ... COBOL (pronounced //) is a third-generation programming language, and one of the oldest programming languages still in active use. ...


A number of bits sufficient for the precision and range required must be chosen to store the fractional and integer parts of a number. For example, using a 32-bit format, 16 bits might be used for the integer and 16 for the fraction.


The fractional bits continue the pattern set by the integer bits: if the eight's bit is followed by the four's bit, then the two's bit, then the one's bit, then of course the next bit is the half's bit, then the quarter's bit, then the ⅛'s bit, et cetera.


Examples:

 integer bits fractional bits 0.5 = ½ = 00000000 00000000.10000000 00000000 1.25 = 1¼ = 00000000 00000001.01000000 00000000 7.375 = 7⅜ = 00000000 00000111.01100000 00000000 

However, using this form of encoding means that some numbers cannot be represented in binary. For example, for the fraction 1/5 (in decimal, this is 0.2), the closest one can get is:

 13107 / 65536 = 00000000 00000000.00110011 00110011 = 0.1999969... in decimal 13108 / 65536 = 00000000 00000000.00110011 00110100 = 0.2000122... in decimal 

And even with more digits, an exact representation is impossible. Consider the number ⅓. If you were to write the number out as a decimal (0.333333...) it would continue indefinitely. If you were to stop at any point, the number written would not exactly represent the number ⅓.


The point is: some fractions cannot be expressed exactly in binary notation... not unless you use a special trick. The trick is, to store a fraction as two numbers, one for the numerator and one for the denominator, and then use arithmetic to add, subtract, multiply, and divide them. However, arithmetic will not let you do higher math (such as square roots) with fractions, nor will it help you if the lowest common denominator of two fractions is too big a number to handle. This is why there are advantages to using the fixed-point notation for fractional numbers.


Floating-point numbers

While both unsigned and signed integers are used in digital systems, even a 32-bit integer is not enough to handle all the range of numbers a calculator can handle, and that's not even including fractions. To approximate the greater range and precision of real numbers we have to abandon signed integers and fixed-point numbers and go to a "floating-point" format. In mathematics, the real numbers may be described informally as numbers that can be given by an infinite decimal representation, such as 2. ... A floating-point number is a digital representation for a number in a certain subset of the rational numbers, and is often used to approximate an arbitrary real number on a computer. ...


In the decimal system, we are familiar with floating-point numbers of the form:

1.1030402 × 105 = 1.1030402 × 100000 = 110304.02

or, more compactly:

 1.1030402E5 

which means "1.103402 times 1 followed by 5 zeroes". We have a certain numeric value (1.1030402) known as a "significand", multiplied by a power of 10 (E5, meaning 105 or 100,000), known as an "exponent". If we have a negative exponent, that means the number is multiplied by a 1 that many places to the right of the decimal point. For example: The significand (also coefficient or mantissa) is the part of a floating-point number that contains its significant digits. ... In mathematics, exponentiation is a process generalized from repeated multiplication, in much the same way that multiplication is a process generalized from repeated addition. ...

2.3434E-6 = 2.3434 × 10-6 = 2.3434 × 0.000001 = 0.0000023434

The advantage of this scheme is that by using the exponent we can get a much wider range of numbers, even if the number of digits in the significand, or the "numeric precision", is much smaller than the range. Similar binary floating-point formats can be defined for computers. There are a number of such schemes, the most popular has been defined by IEEE (Institute of Electrical & Electronic Engineers, a US professional and standards organization). The IEEE 754 standard specification defines a 64 bit floating-point format with: The Institute of Electrical and Electronics Engineers or IEEE (pronounced as eye-triple-ee) is an international non-profit, professional organization incorporated in the State of New York, United States. ... The IEEE Standard for Binary Floating-Point Arithmetic (IEEE 754) is the most widely-used standard for floating-point computation, and is followed by many CPU and FPU implementations. ...

  • an 11-bit binary exponent, using "excess-1023" format. Excess-1023 means the exponent appears as an unsigned binary integer from 0 to 2047, and you have to subtract 1023 from it to get the actual signed value
  • a 52-bit significand, also an unsigned binary number, defining a fractional value with a leading implied "1"
  • a sign bit, giving the sign of the number.

Let's see what this format looks like by showing how such a number would be stored in 8 bytes of memory:

 byte 0: S x10 x9 x8 x7 x6 x5 x4 byte 1: x3 x2 x1 x0 m51 m50 m49 m48 byte 2: m47 m46 m45 m44 m43 m42 m41 m40 byte 3: m39 m38 m37 m36 m35 m34 m33 m32 byte 4: m31 m30 m29 m28 m27 m26 m25 m24 byte 5: m23 m22 m21 m20 m19 m18 m17 m16 byte 6: m15 m14 m13 m12 m11 m10 m9 m8 byte 7: m7 m6 m5 m4 m3 m2 m1 m0 

where "S" denotes the sign bit, "x" denotes an exponent bit, and "m" denotes a significand bit. Once the bits here have been extracted, they are converted with the computation:

<sign> × (1 + <fractional significand>) × 2<exponent> - 1023

This scheme provides numbers valid out to about 15 decimal digits, with the following range of numbers:

maximum minimum
positive 1.797693134862231E+308 4.940656458412465E-324
negative -4.940656458412465E-324 -1.797693134862231E+308

The spec also defines several special values that are not defined numbers, and are known as NaNs, for ‘Not A Number’. These are used by programs to designate invalid operations and the like. You will rarely encounter them and NaNs will not be discussed further here. Some programs also use 32-bit floating-point numbers. The most common scheme uses a 23-bit significand with a sign bit, plus an 8-bit exponent in "excess-127" format, giving 7 valid decimal digits. In computing, NaN (Not a Number) is a value or symbol that is usually produced as the result of an operation on invalid input operands, especially in floating-point calculations. ...

 byte 0: S x7 x6 x5 x4 x3 x2 x1 byte 1: x0 m22 m21 m20 m19 m18 m17 m16 byte 2: m15 m14 m13 m12 m11 m10 m9 m8 byte 3: m7 m6 m5 m4 m3 m2 m1 m0 

The bits are converted to a numeric value with the computation:

<sign> × (1 + <fractional significand>) × 2<exponent> - 127

leading to the following range of numbers:

maximum minimum
positive 3.402823E+38 2.802597E-45
negative -2.802597E-45 -3.402823E+38

Such floating-point numbers are known as "reals" or "floats" in general, but with a number of inconsistent variations, depending on context:


A 32-bit float value is sometimes called a "real32" or a "single", meaning "single-precision floating-point value".


A 64-bit float is sometimes called a "real64" or a "double", meaning "double-precision floating-point value".


The term "real" without any elaboration generally means a 64-bit value, while the term "float" similarly generally means a 32-bit value.


Once again, remember that bits are bits. If you have 8 bytes stored in computer memory, it might be a 64-bit real, two 32-bit reals, or 4 signed or unsigned integers, or some other kind of data that fits into 8 bytes.


The only difference is how the computer interprets them. If the computer stored four unsigned integers and then read them back from memory as a 64-bit real, it almost always would be a perfectly valid real number, though it would be junk data.


So now our computer can handle positive and negative numbers with fractional parts. However, even with floating-point numbers you run into some of the same problems that you did with integers:

  • As with integers, you only have a finite range of values to deal with. Granted, it is a much bigger range of values than even a 32-bit integer, but if you keep multiplying numbers you'll eventually get one bigger than the real value can hold and have a numeric overflow.

If you keep dividing you'll eventually get one with a negative exponent too big for the real value to hold and have a numeric underflow. Remember that a negative exponent gives the number of places to the right of the decimal point and means a really small number. The maximum real value is sometimes called "machine infinity", since that's the biggest value the computer can wrap its little silicon brain around.

  • A related problem is that you have only limited "precision" as well. That is, you can only represent 15 decimal digits with a 64-bit real. If the result of a multiply or a divide has more digits than that, they're just dropped and the computer doesn't inform you of an error.

This means that if you add a very small number to a very large one, the result is just the large one. The small number was too small to even show up in 15 or 16 digits of resolution, and the computer effectively discards it. If you are performing computations and you start getting really insane answers from things that normally work, you may need to check the range of your data. It's possible to "scale" the values to get more accurate results. It also means that if you do floating-point computations, there's likely to be a small error in the result since some lower digits have been dropped. This effect is unnoticeable in most cases, but if you do some math analysis that requires lots of computations, the errors tend to build up and can throw off the results. The fraction of people who use computers for doing math understand these errors very well, and have methods for minimizing the effects of such errors, as well as for estimating how big the errors are. By the way, this "precision" problem is not the same as the "range" problem at the top of this list. The range issue deals with the maximum size of the exponent, while the resolution issue deals with the number of digits that can fit into the significand.

  • Another more obscure error that creeps in with floating-point numbers is the fact that the significand is expressed as binary fraction that doesn't necessarily perfectly match a decimal fraction.

That is, if you want to do a computation on a decimal fraction that is a neat sum of reciprocal powers of two, such as 0.75, the binary number that represents this fraction will be 0.11, or ½ + ¼, and all will be fine. Unfortunately, in many cases you can't get a sum of these "reciprocal powers of 2" that precisely matches a specific decimal fraction, and the results of computations will be very slightly off, way down in the very small parts of a fraction. For example, the decimal fraction "0.1" is equivalent to an infinitely repeating binary fraction: 0.000110011 ...


Numbers in programming languages

Low-level programmers have to worry about unsigned and signed, fixed and floating-point numbers. They have to write wildly different code, with different opcodes and operands, to add two floating point numbers compared to the code to add two integers. Microprocessors perform operations using binary bits (on/off/1or0). ... In mathematics, an operand is one of the inputs (arguments) of an operator. ...


However, high-level programming languages such as LISP and Python offer an abstract number that may be an expanded type such as rational, bignum, or complex. Programmers in LISP or Python (among others) have some assurance that their program code will Do The Right Thing with mathematical operations. Due to operator overloading, mathematical operations on any number—whether signed, unsigned, rational, floating-point, fixed-point, integral, or complex—are written exactly the same way. Others languages such as REXX and Java provide decimal floating-point which avoids many 'unexpected' results. A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. ... For the programming language, see Lisp (programming language). ... Python is a high-level programming language first released by Guido van Rossum in 1991. ... In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. ... REXX (Restructured Extended Executor) is a programming language which was developed at IBM, and several implementations are available under open source licenses. ... “Java language” redirects here. ...


Footnotes

  1. ^ The number of possible symbols needed to represent a range of numbers is most often minimal for base 3, although binary is close in this measure. Since no substantial advantage emerged from this fact, use of base 3 for computers has not been actively pursued. See Brian Hayes, "Third Base", American Scientist 89(6): 490-494 (2001), [1].

See also

The binary numeral system, or base-2 number system, is a numeral system that represents numeric values using two symbols, usually 0 and 1. ... In mathematics and computer science, hexadecimal, base-16, or simply hex, is a numeral system with a radix, or base, of 16, usually written using the symbols 0–9 and A–F, or a–f. ... The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. ... A numeral is a symbol or group of symbols, or a word in a natural language that represents a number. ...

Resources

  • Computer Math Forum
  • Online Char, HEX, Binary, Base64, etc... Encoder/Decoder

The initial version of this article was based on a public domain article from Greg Goebel's Vectorsite. The public domain comprises the body of all creative works and other knowledge&#8212;writing, artwork, music, science, inventions, and others&#8212;in which no person or organization has any proprietary interest. ...


  Results from FactBites:
 
Negative and non-negative numbers (818 words)
A signed number is a number which has either a positive or negative sign (or in the case of zero, neither).
Zero is not a positive number, though in computing zero is sometimes treated as though it were a positive number (due to the way that numbers are typically represented).
On a computer, the sign of a number (whether it is positive or negative) is usually expressed using the left-most bit.
Computer science | Topic Definition | Find the Meaning and Define the Answer of Computer science (1013 words)
Computer science (informally: CS or compsci) is, in its most general sense, the study of computation and information processing, both in hardware and in software.
Computer science encomposses a variety of topics relating to computation, ranging from abstract analysis of algorithms and formal grammars, to subjects like programming languages, software, and computer hardware.
Computer graphics is the field of visual computing, where one utilizes computers both to generate visual images synthetically and to integrate or alter visual and spatial information sampled from the real world.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.