If quitters never win, and winners never cheat, who's the idiot that said: Quit while you're ahead?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
I meant to play with this over the weekend but took a nap instead.
You need to set the left & right "nibbles" of a packed byte independently. The "or" operator will let you do this. So to pack 321 ...
That gives us two bytes '321F'.
Now we have to figure out some kind of loop that will step through the digits of the input and step through an array of output bytes. We can get the digits from an int like this:
This is a bit yucky. We can also get them with something like this:
This takes advantage of knowing that the character "1" is x'31' in ASCII and we can subtract the 30. Coming from mainframe EBCEDIC background, it took me years to be comfortable with relying on ASCII.
Some times we have mix our digit into the LEFT nibble of the output byte. We can shift an int to do that.
Whew. Are you seeing any light at the end of the tunnel? This explored some manipulation but didn't yet suggest what the loop will look like. Lemme know if this was something you can use to get to the next step.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi