• 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

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 16:06 Go to last post