Shop OBEX P1 Docs P2 Docs Learn Events
Binary to BCD — Parallax Forums

Binary to BCD

4x5n4x5n Posts: 745
edited 2012-12-02 16:11 in Propeller 1
Sorry for the post but the forum and obex search ability is somewhat limited and didn't turn anything up. I'm looking for a propeller routine/object to convert binary to bcd. Thought I'd try here before trying to write my own.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-02 07:32
    How much binary? How many digits of BCD? For what purpose? This is a basic programming exercise with a lot of variation depending on the purpose. Any routine that converts binary to characters for display essentially does the same thing, so the DEC routine in most display objects will do this sort of conversion. For example, to get a byte with two digits of BCD in it for setting most RTCs, you'd have:

    BCD_Value := ((Binary / 10) << 4) + (Binary // 10) ' Takes a binary value from 0 to 99 and converts to two digits packed into one byte
  • 4x5n4x5n Posts: 745
    edited 2012-12-02 16:11
    Mike,

    Thanks for the response. Sorry for posting the question and then leaving I intended to delete it after seeing similar topics. Alas, I went to the Bears game today the people I went with arrived a bit early and I had to leave.

    I was asked to make some changes to code I wrote better then 20yrs ago written for the 68hc11 doing interrupt driven machine control. It's been a long time since I looked at it but it was very large very tight code and I thought I might be better rewriting it for a propeller. The binary to bcd conversion was for a two digit 7 seg display. It was my initial concern as I was thinking through and remembering how the code I had written worked.

    While watching the Bears lose today I came to the decision that I really don't want to port the code from the hc11 to the prop and I'll be better off simply modifying the code that already exists. Thanks again for the response.
Sign In or Register to comment.