Decimal to binary in HP Prime
04-16-2019, 10:27 PM (This post was last modified: 04-18-2019 12:00 AM by Albert Chan.)
Post: #3
 Albert Chan Senior Member Posts: 1,588 Joined: Jul 2018
RE: Decimal to binary in HP Prime
I try this in XCas:

bits(x) := convert(convert(trunc(x),base,2),base,10)

x = exact(3.2672) -> 2042/625

bits(x * 2^22) -> 110100010001100111001110

3.2672 ~ 0b11.0100010001100111001110 (24 bits)

For *exact* conversion, we need to get number of repeated bits:

order(a,n) := {local k=0, t=1 mod n; repeat t*=a; k++ until t=1; k}

Since denominator is odd, we can get repeated bits = order(2,625) = 500

bits(x * 2^500), we got:

x = 0b11.(
01000100011001110011100000011101011111011011111101
00100001111111110010111001001000111010001010011100
01110111100110100110101101010000101100001111001001
11101110110010111111101100010101101101010111001111
10101010110011011001111010000011111001000010010110
10111011100110001100011111100010100000100100000010
11011110000000001101000110110111000101110101100011
10001000011001011001010010101111010011110000110110
00010001001101000000010011101010010010101000110000
01010101001100100110000101111100000110111101101001)
 « Next Oldest | Next Newest »

 Messages In This Thread Decimal to binary in HP Prime - jrozsas - 04-16-2019, 05:02 PM RE: Decimal to binary in HP Prime - KeithB - 04-16-2019, 07:16 PM RE: Decimal to binary in HP Prime - Albert Chan - 04-16-2019 10:27 PM

User(s) browsing this thread: 1 Guest(s)