Your functions are backwards... #1
Comments
@abferm First, thanks for taking a look! I'd forgotten about this module :-) These functions implement 'natural' binary-coded decimal: http://en.wikipedia.org/wiki/Binary-coded_decimal#Basics So the functions handle the encoding/decoding per-nibble, and the BCD should be treated as a string (not obvious from the source - I hadn't really expected reuse of this module ;-) and you need to take a look at the binary to see what's going on. So for the doctest:
The integer
Broken down into nibbles for BCD
When you see the BCD as a string, int 34 -> bcd "22". I'll add some documentation so that this behaviour is a little more obvious. Again, thanks for taking a look! |
I think I was misinterpreting what your methods were trying to do. From my understanding int_to_bcd would return the bcd equivalent of the provided integer, not decode an integer as BCD. In other words I expected int_to_bcd(22) to return binary 0010 0010 which is integer 34. ----- Original Message -----
|
Ah, that makes sense. How do additional int_to_binary_bcd and binary_bcd_to_int functions sound? Clearer input/outputs, I think... |
Possibly, I'm surprised that yours is the only BCD library I could find without a whole lot of searching. Would you consider adding an init.py file to make it a true module? ----- Original Message -----
|
Well, binary coded decimals are by nature higher than their integer counterparts... If you swap the names on your functions you will be good to go according to my math.
The text was updated successfully, but these errors were encountered: