Post Reply 
HP 50g Binary Number Formatting
04-24-2022, 11:59 AM
Post: #9
RE: HP 50g Binary Number Formatting
(04-24-2022 10:40 AM)3298 Wrote:  ...
The rest is just putting the string pieces together and converting the most significant digit group using one of the normal convert-to-string commands because that one is allowed to omit leading zeroes.
...

Wow, every time I get ready to post a response on this thread, someone posts something that makes it look as if I were plagiarizing.

I took a different view to this, mostly because I prefer to see full groups of 4 (ie. with leading zeros) instead of a shortened version for the initial digit group. In other words, I would prefer to convert #1Fh to "0001 1111" than "1 1111".

My standard UserRPL version of this would seem redundant given the previous posts. So instead I'll submit a version that uses some of the ListExt library commands to shorten the code:
Code:
\<<
   RCLF BIN                   @ save modes and set to binary
   SWAP \->STR                @ convert binary # to base-2 string
   SWAP STOF                  @ restore modes
   3.                         @ starting char to keep
   OVER SIZE 1. -             @ last char to keep
   SUB                        @ extract just the digits

   "000" SWAP +               @ left-pad with zeros
   S\->SL                     @ convert string to list of characters
   DUP SIZE 4. MOD LDROP      @ drop unwanted prefix characters
   4. LSDIV                   @ group all digit characters into quads
   " " LMAP                   @ place spaces after each group
   -1. LDROP                  @ drop the final space
   LXIL SL\->S                @ convert chars to final string
\>>

Size: 112.5 bytes
Checksum: # 1A0Bh

Descriptions of the ListExt commands used:
S→SL: Converts a string to a list of individual characters
LDROP: Drops the specified quantity of list elements from a given list (positive drops from the left, negative from the right)
LSDIV: Subdivides a given list into a list of sublists with the given size
LMAP: Executes the given object for each list element, and returns the results as a list
LXIL: (eXplode Inner Lists) replaces top-level sublists with the individual elements they contain
SL→S: builds a string from the given list of characters
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 50g Binary Number Formatting - aaron - 04-20-2022, 05:47 PM
RE: HP 50g Binary Number Formatting - Gil - 04-23-2022, 01:38 PM
RE: HP 50g Binary Number Formatting - Gil - 04-23-2022, 06:01 PM
RE: HP 50g Binary Number Formatting - Gil - 04-23-2022, 06:50 PM
RE: HP 50g Binary Number Formatting - Gil - 04-24-2022, 12:03 AM
RE: HP 50g Binary Number Formatting - 3298 - 04-24-2022, 10:40 AM
RE: HP 50g Binary Number Formatting - DavidM - 04-24-2022 11:59 AM
RE: HP 50g Binary Number Formatting - Gil - 04-24-2022, 11:34 AM
RE: HP 50g Binary Number Formatting - Gil - 04-25-2022, 04:04 PM
RE: HP 50g Binary Number Formatting - Gil - 04-25-2022, 10:34 PM



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