(15C) another approach to decimal <> binary conversion

11292017, 10:32 AM
(This post was last modified: 11292017 04:31 PM by jthole.)
Post: #1




(15C) another approach to decimal <> binary conversion
This is my first try at creating a useful RPN program, so any comments for improvement are welcome!
A well known strategy for representing a decimal number in binary notation, is to keep dividing by two, and placing a "1" if the fractional part > 0, and a "0" if the fraction is 0. At the end of the conversion, the binary result is the output read backwards. That works well for uneven numbers, but you will lose zeros for even numbers. I've written my own conversion (not using an existing program as the basis, so I surely have made beginner mistakes), which prefixes the number with a "8". That makes sure the leading zeros are preserved, and can be easily read as "B" for binary ;) This program takes 20 steps, and uses storage register 0 for intermediate results. Since I am still waiting for the DM15L to arrive, I tested this in the following HP 15C emulators:  Touch 15C on Android  The online hp15c.com emulator Code: 001 8 To start the program, input the decimal number you want to convert (no need to press enter), and press R/S. The binary number is returned in the X register (in reverse). Here's the same program for the HP 12C: Code: 01 8 

« Next Oldest  Next Newest »

Messages In This Thread 
(15C) another approach to decimal <> binary conversion  jthole  11292017 10:32 AM
RE: (15C) another approach to decimal <> binary conversion  Dieter  11302017, 07:50 PM
RE: (15C) another approach to decimal <> binary conversion  jthole  12012017, 08:48 AM
RE: (15C) another approach to decimal <> binary conversion  Thomas Klemm  09012018, 06:16 PM

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