Syntax:
DectoBcd( ByteVariable )
Command Availability:
Available on all microcontrollers.
Explanation:
Converts numbers from decimal to Binary Coded Decimal (BCD) format. Supports bytes only. In BCD, each nibble (4 bits) of a
byte represents one decimal digit — for example, the decimal number 23 becomes the BCD byte 0x23.
This is not a built-in GCBASIC command; it is a user-defined function you add to your own program and call when needed.
Example:
Function DecToBcd(va) as Byte
DecToBcd=(va/10)*16+va%10 ' <<< the DecToBcd instruction
End FunctionKey line: DecToBcd=(va/10)*16+va%10 — splits the decimal value va into tens and units, then packs the tens digit into the high nibble and the units digit into the low nibble of the result
byte.
See Also:
- BcdToDec_GCB — the inverse conversion

