Proton BASIC Compiler - BCD to BIN array conversion


  • PicŪ Basic


  • BCD to BIN array conversion

    There are times when you have to enter a number via a keypad. The inputting of the number is a relatively easy affair using a number accumulator (See Password Controlled Entry Module on this site for more details). Then is often the case that you have to convert that array to a number.

    Presuming you entered the number highest first 1,2,3,4 for the number 1234, you array will hold the numbers 1,2,3,4 with 1 being at element 0 of the array.

    The following code will convert the array to a Binary number.

    For it to work the pointer has to be pointing to the last element of the array that holds a number. This is often the case on exiting the routine that loaded the array.

    Example Code

    Code:
    Dim Multiplier as Dword
    Dim Result as Dword 
    Dim Pointer as Byte
     
    Multiplier = 10 ' The starting multiplier value 
     
    Result = Array[Pointer] ' Load in the lowest digit
     
    Repeat ' Loop
    Dec Pointer ' Move to next element 
    Result = Result + (Array[Pointer] * Multiplier)
    Multiplier = Multiplier * 10 ' Increase the multiplier
    Until Pointer = 0
    contributed by Timothy Box.
  • Recent Activity

    BobS-112245

    Adin Problem, PIC16F753

    Thread Starter: BobS

    Firstly, my apologies if the presentation is a little messy, its my first posting. I have written a small program (see listing below) for the...

    BobS Yesterday, 17:15 Go to last post
    charliecoultas-16125

    Peripheral Pin Remapping

    Thread Starter: charliecoultas

    Guys I need a little help. I get an error "COUT_PIN_RP140 Not found" and "CIN_PIN_RP141 Not found" with this setup: Device = 33EP512GP806 ...

    charliecoultas Yesterday, 17:08 Go to last post