# 21 binary number system in computer science

For example, is divisible by 2 twice, and is divisible by 2 zero times. The number of times that 1, 2, OEIS A , which is the binary carry sequence. Real numbers can also be represented using binary notation by interpreting digits past the "decimal" point as negative powers of two, so the binary digits would represent the number. The sequence of binary digits for the integers , 1, Unfortunately, the storage of binary numbers in computers is not entirely standardized.

Because computers store information in 8- bit bytes where a bit is a single binary digit , depending on the "word size" of the machine, numbers requiring more than 8 bits must be stored in multiple bytes.

However, a number represented as byte1 byte2 byte3 byte4 in a VAX would be read and interpreted as byte4 byte3 byte2 byte1 on a Sun.

The situation is even worse for floating-point real numbers, which are represented in binary as a mantissa and characteristic , and worse still for long 8-byte reals! Binary multiplication of single bit numbers 0 or 1 is equivalent to the AND operation, as can be seen in the following multiplication table. Consider the cumulative digit sum of all binary numbers up to 1, 2, The first few terms are then 1, 2, 4, 5, 7, 9, 12, 13, 15, 17, 20, 22, This sequence in monotonic increasing left figure , but if the main asymptotic term is removed, a sequence of humped curves right figure; Trott , p.

Computers represent data in sets of binary digits. The representation is composed of bits, which in turn are grouped into larger sets such as bytes. A bit is a binary digit that represents one of two states. The concept of a bit can be understood as a value of either 1 or 0 , on or off , yes or no , true or false , or encoded by a switch or toggle of some kind.

While a single bit, on its own, is able to represent only two values, a string of bits may be used to represent larger values. For example, a string of three bits can represent up to eight distinct values as illustrated in Table 1. As the number of bits composing a string increases, the number of possible 0 and 1 combinations increases exponentially. While a single bit allows only two value-combinations and two bits combined can make four separate values and so on.

The amount of possible combinations doubles with each binary digit added as illustrated in Table 2. Groupings with a specific number of bits are used to represent varying things and have specific names. A byte is a bit string containing the number of bits needed to represent a character. On most modern computers, this is an eight bit string. Because the definition of a byte is related to the number of bits composing a character, some older computers have used a different bit length for their byte.

For example, even though bit processors may address memory sixty-four bits at a time, they may still split that memory into eight-bit pieces. This is called byte-addressable memory. Historically, many CPUs read data in some multiple of eight bits. A nibble sometimes nybble , is a number composed of four bits. A person may need several nibbles for one bite from something; similarly, a nybble is a part of a byte. Because four bits allow for sixteen values, a nibble is sometimes known as a hexadecimal digit.

Octal and hex are convenient ways to represent binary numbers, as used by computers. Computer engineers often need to write out binary quantities, but in practice writing out a binary number such as is tedious and prone to errors.

Therefore, binary quantities are written in a base-8, or "octal", or, much more commonly, a base, "hexadecimal" or "hex", number format. In the decimal system, there are 10 digits, 0 through 9, which combine to form numbers. In an octal system, there are only 8 digits, 0 through 7. That is, the value of an octal "10" is the same as a decimal "8", an octal "20" is a decimal "16", and so on. In a hexadecimal system, there are 16 digits, 0 through 9 followed, by convention, with A through F.

That is, a hex "10" is the same as a decimal "16" and a hex "20" is the same as a decimal "32". An example and comparison of numbers in different bases is described in the chart below. 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 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.

Fixed-point formatting can be useful to represent fractions in binary. The number of bits needed for the precision and range desired must be chosen to store the fractional and integer parts of a number.

For instance, using a bit format, 16 bits may be used for the integer and 16 for the fraction. The eight's bit is followed by the four's bit, then the two's bit, then the one's bit. A bit float is sometimes called a "real64" or a "double", meaning "double-precision floating-point value". The relation between numbers and bit patterns is chosen for convenience in computer manipulation; eight bytes stored in computer memory may represent a bit real, two bit reals, or four signed or unsigned integers, or some other kind of data that fits into eight 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 bit real, it almost always would be a perfectly valid real number, though it would be junk data. Only a finite range of real numbers can be represented with a given number of bits. Arithmetic operations can overflow or underflow, producing a value too large or too small to be represented. The representation has a limited precision.

For example, only 15 decimal digits can be represented with a bit real. If a very small floating-point number is added to a 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. Analyzing the effect of limited precision is a well-studied problem. Estimates of the magnitude of round-off errors and methods to limit their effect on large calculations are part of any large computation project.

The precision limit is different from the range limit, as it affects the significand, not the exponent. The significand is a binary fraction that doesn't necessarily perfectly match a decimal fraction. In many cases a sum of reciprocal powers of 2 does not matches a specific decimal fraction, and the results of computations will be slightly off. For example, the decimal fraction "0. Programming in assembly language requires the programmer to keep track of the representation of numbers.

Where the processor does not support a required mathematical operation, the programmer must work out a suitable algorithm and instruction sequence to carry out the operation; on some microprocessors, even integer multiplication must be done in software. 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.

Mathematical operations are carried out by library routines provided by the implementation of the language. A given mathematical symbol in the source code, by operator overloading , will invoke different object code appropriate to the representation of the numerical type; mathematical operations on any number—whether signed, unsigned, rational, floating-point, fixed-point, integral, or complex—are written exactly the same way.

Some languages, such as REXX and Java , provide decimal floating points operations, which provide rounding errors of a different form. The initial version of this article was based on a public domain article from Greg Goebel's Vectorsite.

From Wikipedia, the free encyclopedia. This article has multiple issues. Please help improve it or discuss these issues on the talk page.

Learn how and when to remove these template messages. This article may need to be rewritten entirely to comply with Wikipedia's quality standards.

The discussion page may contain suggestions. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.

February Learn how and when to remove this template message. Positional notation Base conversion.