Re: Binary number digits <- > Decimal number digits



On Sun, 9 Dec 2007 09:28:13 -0800 (PST), mensanator@xxxxxxxxxxx wrote:

On Dec 9, 10:50?am, Jeremy Boden <jer...@xxxxxxxxxxxxxxx> wrote:
On Sun, 09 Dec 2007 16:58:11 +0100, Helmut Richter wrote:
On Sun, 9 Dec 2007, fc wrote:

For example, what calculus was made to arrive that a decimal number of
617 digits must have 2048 digits in binary? (Obviously, without make
the conversion of the decimal number 999999...99999 [617 9 numbers] to
binary) And: how to generalize for any decimal number of any length?

The number of digits of x in some base b is, not regarding rounding to
integers, the logarithm of x with respect to base b, which is ?log x /
log b (log to arbitrary base).

So the number of decimal digits of x is ?log 2 / log 10 = 0.30103 .

For a rough calculation, 2^10 = 1024,
So 10 bits is approximately 3 digits.

How come you didn't round up?

Rounding up is appropriate in this case -- for the value 1024.

It is not always appropriate -- for an arbitrary n-bit value.

The following is an incomplete question:
"How many decimal digits are available from an n-bit binary number?"

What does the questioner mean by "How many?"

Do they mean "at _most_ 'x' digits"? If so, we always round up.

Or do they mean "at _least_ 'x' digits"? If so, we might round down.

Let's take a closer look at a 10-bit integer.

1023 is an unsigned 10-bit integer in which all bits are set:

11 1111 1111 (binary) = 1023 (decimal) -- four decimal digits.

10 * log(2)/log(10) = 3.01

Rounding up may suggest that we can always get 4 decimal digits from a
10-bit integer when the highest-order bit is in use.

But such is not the case.

512 is also an unsigned 10-bit integer -- it requires the use of the
highest order bit in a 10-bit integer, which is 2^9:

10 0000 0000 (binary) = 512 (decimal) -- three decimal digits.


The following are true statements:

1. We can get _at most_ 4 decimal digits from a 10-bit unsigned
integer.

2. We can get _at least_ 3 decimal digits from a 10-bit unsigned
integer when the highest-order bit is in use.

Whether we round the digit-conversion calculation up or down may
depend on:
1. What we're after when we ask "how many digits"?
2. The width of the binary representation -- which determines the
fractional part in the result of n * log 2 / log 10. It may be that
when this fractional part is "large enough", we round up for either
case.


On Sun, 9 Dec 2007 07:39:24 -0800 (PST), fc wrote:
And: how to generalize for any decimal number of any length?

Consider the following two 5-digit decimal numbers:

expression decimal number bits required
2^16 - 1 65,535 16
2^16 + 2^14 81,920 17

5 * log(10) / log(2) = 16.6

Round up or down comes into play again.


Adam

--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: XQ and ->Qpi bug on large X
    ... you shouldn't be rounding to only two digits ... I am trying to make a similar point here about rounding; ... and round it, ... prior to using the input values in calculations. ...
    (comp.sys.hp48)
  • Re: Decimall Float Question
    ... the number other than to round the decimal part. ... 'bankers rounding' to the nearest even number is not required). ... the FAQ code includes having a variable number of digits after ... // Convert number to string and split ... ...
    (comp.lang.javascript)
  • Re: check decimal and if numeric
    ... so effectively truncates an subsequent digits for positive numbers. ... It's different when you round negative numbers down, ... decimals, who's to say the third or fourth digit was the one that was in error? ...
    (microsoft.public.access.formscoding)
  • =?Utf-8?Q?Re:_I_don=C2=B4t_view_the_value_right?= =?Utf-8?Q?_after_six_decimal_place_in_Exce
    ... Excel does by default, but instead you wanted to round down or truncate, you ... Presumably MS chose not to display more than 15 digits because not ALL 16 ...
    (microsoft.public.excel.misc)
  • Re: Fastcode RoundTo B&V 0.1
    ... Should the name and sign convention for number decimal fraction "Digits" ... {Round to nearest else to even digit. ... Function DecimalRound( ...
    (borland.public.delphi.language.basm)