Binary scaling

Binary scaling

Binary scaling is a computer programming technique used mainly by embedded C, DSP and assembler programmers to perform a pseudo floating point using integer arithmetic.It is both faster and more accurate than directly using floating point instructions, however care must be taken not to cause an overflow.

A position for the virtual 'binary point' is taken, and then subsequent arithmetic operationsdetermine the resultants 'binary point'.

Binary points obey the mathematical laws of exponentiation.

To give an example, a common way to use integer maths to simulate floating point is to multiply the co-efficients by 65536. This is currently used in the microwindows utility nxcal to linearise the output of touchscreens.

This will place the binary point at B16.

For instance to represent 1.2 and 5.6 floating point real numbers as B16 one multiplies them by 216 giving

78643 and 367001

Multiplying these together gives


To convert it back to B16, divide it by 216.

This gives 440400B16, which when converted back to a floating point number (by dividing again by 216, but holding the result as floating point) gives 6.71999.The correct floating point result is 6.72.

The scaling range here is for any number between 65535.9999 and -65536.0 with 16 bits to hold fractional quantities (of course assuming the use of a 64 bit result register). Note that some computer architectures may restrict arithmetic to 32 bit results. In this case extreme care must be taken not to overflow the 32 bit register. For other number ranges the binary scale can be adjusted for optimum accuracy.

Re-scaling after multiplication

The example above for a B16 multiplication is a simplified example. Re-scaling depends on both the B scale value and the word size. B16 is often used in 32 bit systems because it works simply by multipling and dividing by 65536 (or shifting 16 bits).

Consider the Binary Point in a 32 bit word thus:

0 1 2 3 4 5 6 7 8 9 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X

Placing the binary point at
* 0 gives a range of -1.0 to 0.999999.
* 1 gives a range of -2.0 to 1.999999
* 2 gives a range of -4.0 to 3.999999 and so on.

When using different B scalings the complete B scaling formula must be used.

Consider a 32 bit word size, and two variables, one with a B scaling of 2 and the other with a scaling of 4.

1.4 @ B2 is 1.4 * (2wordsize-2-1) = 1.4 * 2 ^ 29 = 0x2CCCCCCD

Note that here the 1.4 values is very well represented with 30 fraction bits! A 32 bit real number has 23 bits to store the fraction in. This is why B scaling is always more accurate than floating point of the same wordsize.This is especially useful in integrators or repeated summing of small quantities where rounding error can be a subtle but very dangerous problem, when using floating point.

Now a larger number 15.2 at B4.

15.2 @ B4 is 15.2 * (2 ^ (wordsize-4-1)) = 15.2 * 2 ^ 27 = 0x7999999A

Again the number of bits to store the fraction is 28 bits. Multiplying these 32 bit numbers give the 64 bit result 0x1547AE14A51EB852

This result is in B7 in a 64 bit word. Shifting it down by 32 bits gives the result in B7 in 32 bits.


To convert back to floating point, divide this by (2^(wordsize-7-1)) = 21.2800000099

Various scalings maybe used. B0 for instance can be used to represent any number between -1 and 0.999999999.

Binary angles

Binary angles are mapped using B0, with 0 as 0 degrees, 0.5 as 90 (or pi/2), -1.0 or 0.9999999 as 180 (or pi) and -0.5 as 270 (or 3.pi/2). When these binary angles are added using normal twos complement mathematics the rotation of the angles is correct, even when crossing the sign boundary (this of course does away with check like (if >= 360.0) when handling normal degrees).

Application of binary scaling techniques

Binary scaling techniques were used in the 1970s and 80s for real time computing that was mathematically intensive, such as flight simulation. The code was often commented with the binary scalings of the intermediate results of equations.

Binary scaling is still used in many DSP applications and custom made microprocessors are usually based on binary scaling techniques.

Binary scaling is currently used in the DCT used to compress JPEG images in utilities such as the GIMP.

Although floating point has taken over to a large degree, where speed and extra accuracy are required, binary scaling is faster and more accurate.

Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Binary-coded decimal — In computing and electronic systems, binary coded decimal (BCD) is a digital encoding method for numbers using decimal notation, with each decimal digit represented by its own binary sequence. In BCD, a numeral is usually represented by four bits …   Wikipedia

  • List of unusual units of measurement — For units of measure primarily used in countries where English is not the main language, see the article specific to that country, a list of which can be found in the systems of measurement article. An unusual unit of measurement is a unit of… …   Wikipedia

  • Fixed-point arithmetic — In computing, a fixed point number representation is a real data type for a number that has a fixed number of digits after (and sometimes also before) the radix point ( e.g. , after the decimal point . in English decimal notation). Fixed point… …   Wikipedia

  • Q (number format) — Q is a fixed point number format where the number of fractional bits (and optionally the number of integer bits) is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits. Q format is… …   Wikipedia

  • Scale factor (computer science) — A scale factor is used in computer science when a real world set of numbers needs to be represented on a different scale in order to fit a specific number format. For instance, a 16 bit unsigned integer ( uint16 ) can only hold a value as large… …   Wikipedia

  • Floating point — In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent …   Wikipedia

  • Rounding — This article is about numerical rounding. For lip rounding in phonetics, see Labialisation. For other uses, see Rounding (disambiguation). Rounding a numerical value means replacing it by another value that is approximately equal but has a… …   Wikipedia

  • Successive approximation ADC — Successive Approximation redirects here. For behaviorist B.F. Skinner s method of guiding learned behavior, see Shaping (psychology). A successive approximation ADC is a type of analog to digital converter that converts a continuous analog… …   Wikipedia

  • Tandem Computers — A Tandem Computers promotional mug Tandem Computers, Inc. was the dominant manufacturer of fault tolerant computer systems for ATM networks, banks, stock exchanges, telephone switching centers, and other similar commercial transaction processing… …   Wikipedia

  • Guttman scale — In statistical surveys conducted by means of structured interviews or questionnaires, a subset of the survey items having binary (e.g., YES or NO) answers forms a Guttman scale (named after Louis Guttman) if they can be ranked in some order so… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”