Re: Binary number digits <- > Decimal number digits



On Dec 9, 3:44 pm, Adam <n...@xxxxxxxx> wrote:
On Sun, 9 Dec 2007 09:28:13 -0800 (PST), mensana...@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.

But that wasn't asked.


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

What was asked was how many bits are required
for an n-digit decimal number.


What does the questioner mean by "How many?"

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

It was _exactly_ 617 decimal digits, with each
digit a 9.


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

Not applicable.


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.

If you have 3.x gallons of water in a tank a
1 gallon bucket to transfer it with, you're going
to make 4 goes regardless of how small x is as long
as x>0.


But such is not the case.

Because you're doing it backwards?


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.

Nope. A 617 digit decimal display will _require_
a 2050-bit register if you plan to shown _every_
possible 617-digit decimal number.

There may be some 617-digit numbers (such as RSA
challenge) that can get away with fewer bits, but
the OP specifically said all 9's, so rounding
down doesn't enter into it.


Adam

--
Posted via a free Usenet account fromhttp://www.teranews.com- Hide quoted text -

- Show quoted text -

.



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: Rounding in VBA - Any ideas?
    ... MS chose not to display more than 15 digits because digits beyond the 15th ... Consider dblContainer*lngExpon which you round to produce ... VBA did what you told it to do, but that is different than what you wanted ... "banker's rounding" than the VBA Round function, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: XQ and ->Qpi bug on large X
    ... did away with the IEEE directed rounding that the HP71 had ... What if the calculator were used for finance ... OTOH: VBScript's Round vs. FormatNumber and Format$: ... stored with 12 total digits is irrelevant. ...
    (comp.sys.hp48)
  • Re: Rounding errors
    ... digits then the average is _NOT_ 0.500. ... Rounding of the original set of long numbers, ... When you round the numbers to two digits what existed beyond the 3rd ... so the truncation doesn't matter. ...
    (comp.lang.cobol)
  • 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)

Loading