Posts: 27
Threads: 1
Joined: Aug 2007
Put the calculator in BASE mode (Orange_shift BASE (over the 3)). Then the Fx keys can switch between the 4 different display formats Hex(F1), Dec(F2), Oct(F3) and Bin(F4). This will change the display of all numbers that are displayed with #xxxxxb.
Posts: 291
Threads: 43
Joined: Jun 2007
Hi again Ken,
This method will work, although it can get a bit tedious...
To convert from a binary fraction to a decimal fraction:
Let's use your example of #.011b: Multiply the binary fractional number by the power of 2 necessary to move the point to the right of the rightmost digit. In our case we need to move the point three places to the right, so we multiply by 2^3, which gives us
#11b. Use the calc to convert this to decimal, which yields 3.
Divide this by 2^3 (to remove it) and we get .375 .
Going the other way is essentially the reverse of the above, take your decimal fraction and start multiplying by increasing powers of 2 until it's an integer (just start hitting 2 multiply while keeping count)...in our case .375 becomes an integer (3) after being multiplied by 2^3 (8). Convert to binary and divide by 2^3 by sliding the point three places to the left.
If your decimal fractional number won't convert to a pure integer by multiplying by increasing powers of two (and most won't), you're looking at a repeating binary fractional number. Carry out the powers of 2 multiplication until you feel you have enough accuracy (2^13 seems like a good place to stop). Example:
To convert .6 decimal to binary: .6 ENTER, 2 multiply repeatedly while counting. Stop at 13 reps (2^13). display reads 4915.2. Convert to binary (calc will round off fractional part of number) to get #1001100110011b, divide by 2^13 by sliding point 13 places to the left to get #.1001100110011...b.
You could write subroutines to help with the tedious aspects of this, but I'll leave that to you.
Best regards, Hal
Posts: 247
Threads: 26
Joined: Oct 2007
There's nothing built in, but I've got a small program that can do these conversions. It's rather unsophisticated, and does no error checking, so garbage in, garbage out, as they say. It'll handle negative numbers; simply include a minus sign as the first character in your string. Either key the program in manually, or transfer with Kermit in ASCII mode.
3: Source base (Real)
2: Destination base (Real)
1: Number (String)
%%HP: T(3)A(R)F(.);
\<<
\<< NUM
IF DUP 64. >
THEN 55. -
ELSE 48. -
END
\>>
\<<
IF DUP 9. >
THEN 55. +
ELSE 48. +
END CHR
\>> 0. 0. 0. 0. 0. 0. 0. 0. \-> SB DB VS CVAL VALC V L DP R ST EN SG N
\<<
IF SB 10. ==
THEN VS OBJ\-> 'V' STO
IF V 0. <
THEN V NEG 'V' STO -1. 'SG' STO
ELSE 1. 'SG' STO
END
ELSE VS SIZE 'L' STO VS "." POS 'DP' STO
IF DP 0. \=/
THEN SB INV 'R' STO DP 1. + L
FOR x VS x DUP SUB CVAL EVAL R * V + 'V' STO R SB / 'R' STO
NEXT DP 1. - 'ST' STO
ELSE L 'ST' STO
END 1. 'R' STO
IF VS 1. 1. SUB "-" ==
THEN -1. 'SG' STO 2. 'EN' STO
ELSE 1. 'SG' STO 1. 'EN' STO
END ST EN
FOR x VS x x SUB CVAL EVAL R * V + 'V' STO R SB * 'R' STO -1.
STEP
END
IF SG -1. ==
THEN "-" 'VS' STO
ELSE "" 'VS' STO
END V LN DB LN / IP DB SWAP ^ 'R' STO 0. 'DP' STO
WHILE V .000000000001 >
REPEAT
IF R 0. > R 1. < AND DP 0. == AND
THEN VS "." + 'VS' STO 1. 'DP' STO
END V R / IP 'N' STO VS N VALC EVAL + 'VS' STO N R * V SWAP - 'V' STO R DB / 'R' STO
END VS
\>>
\>>
Checksum (from a 48GX): #EA1Eh