Chapter 15. Binary-Coded Decimal (BCD)
Converting an ASCII string to binary-coded decimal is as easy as pie (or is it a piece of cake?). In BCD, for every byte, the lower 4-bit nibble and upper 4-bit nibble each store a value from 0 to 9 (think double-digit hex only the upper six values A through F are ignored).
Workbench Files:\Bench\x86\chap15\project\platform
project | platform | |
ASE to VMP | \ase2vmp\ | \vc6 |
BCD 2N | \bcd\ | \vc.net |
BCD
Table 15-1. ASCII numerical digit to hex and decimal values
ASCII | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Hex | 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 |
Decimal | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
BCD | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 |
Converting a BCD value from ASCII to a nibble is as easy as subtracting the hex value of 0x30, '0', or 48 decimal from the ASCII ...
Get 32/64-Bit 80x86 Assembly Language Architecture now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.