Are there any limitations when going from binary to decimal (just as when going from decimal to binary)?
As we all know, not all decimal numbers can be represented in binary (with a finite number of digits).
I'm wondering, can all (finite) binary numbers be represented using (a finite number of) decimal digits? I suspect so, since all "primitives" in binary ("0.5", "0.125", etc) can be represe开发者_如何学JAVAnted with a finite number of decimal digits.
So, my question is the following: What characterizes a "compatible base-change"? I.e., what are the mathematical properties that hold for "Base 2 → Base 10" but does not hold for "Base 10 → Base 2"?
(Put formally: What properties must N and M have, in order to ensure that all finite Base-N numbers have a corresponding finite Base-M number?)
If n is a binary fraction, then n = a / 2k for integers a and k.
That means that n = (a · 5k) / (2k · 5k) = (a · 5k) / 10k
So every binary fraction is a decimal fraction.
In the general case, every fraction to base N is also a fraction to base M if and only if N divides Mk for some k (or, equivalently, if every prime factor of N is also a prime factor of M). An argument similar to the one I gave above for 2 and 10 handles the "if" direction. For the "only if" direction, here's a sketch proof for you to fill in: suppose that 1 / N = a / Mk, then Mk = a · N, therefore N divides Mk.
So binary can be converted to decimal without loss because 2 is factor of 10, but decimal cannot be converted to binary without loss, because 5 is a factor of 10 but not a factor of 2.
精彩评论