It is very eazy to convert an integer number to another base, say 2, using Maple. Can anyone tell me how to convert a rational numbers with several decimals from base 10 to other bases In maple? Well, I can multiply the rational number by 10th and get integer and then convert to another base, but this wont give me the true value for corresponding number in the other base. For example, I can multiply 0.25 by 10 and get 25 and after that convert 25 from base 10 to base 2 and get 10011 but this doesn't equal 0.25 in base 2. Cam anyone tell me how to do that in Maple?? Thank you.
how to convert to a rational number with some decimal from base 10 to base 2
1.6k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
You wrote that you wanted to convert "rational numbers with several decimals", which is not clear.
Did you mean that you want to convert base-10 floating-point numbers (with several decimal digits on the right of the point) to base-2?
If that is so, then is this what you are trying to get for the 0.25 example?
convert(0.25,binary);
0.01000000000
The above method can be used for any base-10 float, to convert to binary (base-2) float representation.
The question of converting other to "floating-point" representation in some other base (radix) is interesting.
restart:
G:=proc(x)
local radix;
if type(procname,indexed) and nops([op(procname)])>0
and type(op(1,procname),posint)
and op(1,procname)>1 then
radix:=op(1,procname);
else
radix:=2;
end if;
parse(cat(op(ListTools:-Reverse(
convert(trunc(x*radix^Digits),base,radix)))))
*10.0^(-Digits);
end proc:
p:=0.5555555555555555555555555555:
G(p), convert(p,binary);
0.1000111000, 0.1000111000
p:=98.7654321:
G(p), convert(p,binary);
6 6
1.100010110 10 , 1.100010110 10
Digits:=30:
p:=98765432.1987654321:
G[2](p), convert(p,binary);
26 26
1.01111000110000101001111000001 10 , 1.01111000110000101001111000001 10
G[8](p), convert(p,octal);
8 8
5.70605170145611124547073676376 10 , 5.70605170145611124547073676376 10
G[3](p); # how shall we test this, to see if all "digits" are accurate?
16
2.02122112102002220121002200220 10
On
How do you find the $r$-ary expansion of any number? Let’s look at the interesting case of a number $\alpha$ between $0$ and $1$. Multiply by $r$ to get a whole-number part $d_1<r$ and a fractional part $\alpha_1$ again between $0$ and $1$. The $d_1$ is your first digit, and now you do the same thing to $\alpha_1$. There’s no mystery here. For whole numbers instead of fractions, you get the successive digits, going leftwards, by repeatedly dividing by $r$ and outputting the remainders.
Couldn't you just do the procedure you outlined (multiply say 0.25 to make it an integer=25) then divide by whatever you multiplied by? (in this case you would divide by 1100100)