Comments (4)
@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:
>>> int_to_bcd(34)
22
The integer
00100010
87654321
bit 2 and bit 6 are 1, which is 2 + 32 = 34
Broken down into nibbles for BCD
0010 0010
Which, referencing the table in Wikipedia, 0020 is 2. "2" + "2" = "22"
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!
from python-bcd.
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 -----
From: "David T. Crosby" [email protected]
Date: Sunday, May 31, 2015 10:17 am
Subject: Re: [python-bcd] Your functions are backwards... (#1)
To: dafyddcrosby/python-bcd [email protected]
Cc: abferm [email protected]
@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:
int_to_bcd(34) > 22 >
The integer
00100010 > 87654321 > bit 2 and bit 6 are 1, which is 2 + 32 = 34 >
Broken down into nibbles for BCD
0010 0010 > Which, referencing the table in Wikipedia, 0020 is 2. "2" + "2" = "22" >
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!
—
Reply to this email directly or view it on GitHub.
-
from python-bcd.
Ah, that makes sense. How do additional int_to_binary_bcd and binary_bcd_to_int functions sound? Clearer input/outputs, I think...
from python-bcd.
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 -----
From: "David T. Crosby" [email protected]
Date: Monday, June 1, 2015 11:25 am
Subject: Re: [python-bcd] Your functions are backwards... (#1)
To: dafyddcrosby/python-bcd [email protected]
Cc: abferm [email protected]
Ah, that makes sense. How do additional int_to_binary_bcd and binary_bcd_to_int functions sound? Clearer input/outputs, I think...
—
Reply to this email directly or view it on GitHub.
-
from python-bcd.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-bcd.