DSPRelated.com
Forums

bits required for decimal values

Started by hurry January 8, 2006
hi,

I would like to calculate the exact number of bits to represent a given
decimal number.

for integers logX with base 2, would do that.

similarly is there anyway to say for decimal numbers (  only for
numbers <1 ).
say, for 0.5 should give 1 and for 0.75 should give a result of 3 and I
dont want to do the long division just to find the bits required.

regards,
hurry.

hurry wrote:
> hi, > > I would like to calculate the exact number of bits to represent a given > decimal number. > > for integers logX with base 2, would do that. > > similarly is there anyway to say for decimal numbers ( only for > numbers <1 ). > say, for 0.5 should give 1 and for 0.75 should give a result of 3 and I > dont want to do the long division just to find the bits required.
Although one can think about fractional bits, they are available to use only in integer amounts. (Unlike decimal digits, which can be fractional in some cases: 3 1/2 digit displays are available.) One bit can represent two states. (You may choose it's meaning: +/-, 1/0, heads/tails, and more.) Two bits can represent four states, but you need two anyway if you want only three. For n states, you need log2(n) bits, rounded up. (You need log10(n) decimal digits, also rounded up.) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
hi Jerry,

thnx for the reply.

Assume, I can have as many bits as I want and now I want a math formula
which gives the number of bits reqd.

correction in my earlier post, for 0.75 ans should b 2 bits and
similarly if I give (0.99...... =~ 1) it should give an output of
infinity.

hurry wrote:
> hi Jerry, > > thnx for the reply. > > Assume, I can have as many bits as I want and now I want a math formula > which gives the number of bits reqd. > > correction in my earlier post, for 0.75 ans should b 2 bits and > similarly if I give (0.99...... =~ 1) it should give an output of > infinity.
What assumptions are you making? What don't you understand? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
hi,

may b I din phrase it properly.

0.5 (in decimal ) = 0.1 (in binary) and number of bits reqd. to
represent it without any truncation or approx is one bit.

0.75 (in decimal ) = 0.11 (in binary) and for xact representation bits
reqd is 2

0.9999... (in decimal) = 0.111.....  ( in binary) and for xact
representation bits reqd is infinity

For a given decimal no. calc. bits reqd. to represnt them uniquely.

in article 1136873657.177035.157370@g14g2000cwa.googlegroups.com, hurry at
hurrynarain@gmail.com wrote on 01/10/2006 01:14:

> hi, > > may b I din phrase it properly.
GAH!! may b I don wan 2 ans dis.
> 0.5 (in decimal ) = 0.1 (in binary) and number of bits reqd. to > represent it without any truncation or approx is one bit. > > 0.75 (in decimal ) = 0.11 (in binary) and for xact representation bits > reqd is 2 > > 0.9999... (in decimal) = 0.111..... ( in binary) and for xact > representation bits reqd is infinity > > For a given decimal no. calc. bits reqd. to represnt them uniquely.
look at it this way: 000 -> 999 is three digits. all of those integers can be (just barely) represented by a 10 bit unsigned binary number: (0 -> 1023) so 3 decimal digits need about 10 bits. log(10)/log(2) = approx 10/3 bits for each decimal digit. add a couple more bits at the end for rounding. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Rephrasing:

i/p range: 0 to 0.99999. step size: 0.00001

Smallest step size which my decimal number can take ( say, 0.00001). I
would like to know number of bits reqd. to represent this number (so, I
can represnt all my decimal i/p )

Is there a method to find number of bits req. to rep. this number
directly without doin long division.

P.S: I dont want to do scaling by 10^5 and find out log2 ( 99999). `coz
inside my loop, step size varies.

 in simple words: for integer for a given value X. do log2 (x)
suggest the same for decimal no.

Rephrasing:

smallest step size is unknown. so, the range is betwn 0.0000..... to
0.9999.....

given 0.75 transmit 11 along with (2) , 2 bits- to be read.
for, 0.125 Tx 001 along with (3) , 3- bits to be read

I wanna Tx lik this and not worried if there is a better way of
transmission.

given 0.125 calculate 3 before coding it into 001 ( 0.001)

Rephrasing:

smallest step size is unknown. so, the range is betwn 0.0000..... to
0.9999.....

given 0.75 no. bitz reqd is 2 .
for, 0.125 bitz reqd. 3

mathematically find the least power of 2 reqd. to represent a given
decimal no.

for int: floor of log2 (x) gives the max power of 2 reqd to represent x

hurry wrote:
> Rephrasing: > > smallest step size is unknown. so, the range is betwn 0.0000..... to > 0.9999..... > > given 0.75 no. bitz reqd is 2 . > for, 0.125 bitz reqd. 3
That depends on your notation. You implicitly assume fixed-point notation. Example: let 0 represent 0.1223456 and 1 represent 0.99123455999. Then the least number of bits to represent 0.99123455999 is 1. In general, if the set of numbers you want to represent contains N elements, then you need ceil( log2(N) ) bits to represent them. The interval [0, 1[ contains infinitely many elements, so, in general, you need infinitely many bits to represent them all.
> mathematically find the least power of 2 reqd. to represent a given > decimal no.
You find this number the same way you did for your two examples. Change the number from decimal to binary base fixed-point representation. Another question: which numbers in the interval [0, 1[ can be represented with N digits in base 2 with fixed-point notation? Regards, Andor