Post Reply 
(16C) show which bits are set in a number
03-04-2019, 06:42 PM
Post: #5
RE: (16C) show which bits are set in a number
thanks very much again, Thomas.

(03-04-2019 05:37 PM)Thomas Klemm Wrote:  I'm not that familiar with the HP-16C, so I was a little surprised that the B? command consumes the x-register.

I was also surprised to find that it can't usefully be used in Run mode, as far as I can see. I'd have thought a shortcut to checking whether bit n is set would be generally useful, other than solely as a branch control in a program.

Without that, if you want to check bit 52, for example, you need to work out mentally that you need WINDOW 6, then count along 4 bits. That's a bit (ahem) error-prone, at least when I do it. Alternatively: "1 52 RLn X<>Y AND". Then LSTx your original number.

That led me to the trivial:
Code:
LBL B
B?
1
0
e.g: "X 52 GSB B"

Perhaps I'm missing something obvious Smile


Quote:I like particularly that its flow is like to a backstitch when returning to the top after displaying the index.

I won't take any credit: it just fell out that way Smile

I liked that I could use #B to initialise the loop index so I stop as soon as I've found all the set bits, without having to check WSIZE bits.


I was going to have it also output #B, but since the original number is preserved, the user can simply do it themselves immediately after, or do "#B LSTx" before.

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (16C) show which bits are set in a number - cdmackay - 03-04-2019 06:42 PM



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