Binary Coded Decimal - BCD
Searched and found nothing...wondering if BCD has not been discussed here before...maybe on the ACE forums (will I ever go back and re-qualify?)...
Anyway, I am using a for-loop to decode BCD data; is that the most efficient way to glean BCD data in Netlinx?
Thx!
Anyway, I am using a for-loop to decode BCD data; is that the most efficient way to glean BCD data in Netlinx?
Thx!
Comments
is this a homework question? Lol
You can use a while loop instead but I don't see any way of not looping through the data if that is what you are trying to avoid. As far as decoding is concerned there is likely various methods to do this depending on how many integers per byte, etc.
Paul
It would be nice to put something more robust together (and include in the Google repository), but I am off and running with what I have for now.
Thx!
// convert one byte define_function integer bcdbyte(char bcd) { return (bcd>>4)*10 + (bcd & $0F); } // convert four bytes define_function long bcdword(long bcd) { integer nib long dec dec = 0 for (nib = 1; nib <= 8; nib++) { dec = dec*10 + ((bcd>>(32-nib*4))&$0F) } return dec }Nice and compact, thanks for the tip! I'll install this and test later today.