(50g) B->I and I->B
|
06-17-2020, 03:16 AM
Post: #1
|
|||
|
|||
(50g) B->I and I->B
Here are two little User RPL programs that convert exact integers into binary numbers and vice versa, without the roundoff errors caused by the R->B and B->R functions. These conversions are trivial to do in System RPL, but that's no fun. Faster and/or shorter alternatives to the following would be delightful to see. The default wordsize of 64 may be assumed.
I->B (Integer to Binary) Input: Any exact integer (no decimal point) between 0 and 2^64-1 Output: The exact equivalent "user binary" (AKA binary number). Example: 2 41 ^ I->B --> #20000000000h (exact, unlike R->B) Code: \<< "#" SWAP + "d" + OBJ\-> \>> B->I (Binary to Integer) Input: Any "user binary" (AKA binary number). Output: The exact equivalent integer. Example: #123456789012345h B->I --> 81985529205302085 (exact, unlike B->R, R->I) Code: \<< PUSH DEC \->STR 3 OVER SIZE 1 - SUB OBJ\-> POP \>> <0|ΙΈ|0> -Joe- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)