How to use the Decimal to BCD tool
- Type or paste the decimal digits into the Decimal digits box, for example 45.
- Select Convert. Select Example to fill in 45 and convert it in one step.
- Read the BCD groups in the Result box. Each group of four bits stands for one digit, in the same order as the input.
- Select Copy to copy the groups, or Clear to enter another number.
How binary-coded decimal works
Binary-coded decimal stores a number digit by digit. Each decimal digit from 0 to 9 is replaced by its 4-bit binary value, 0000 to 1001. The weights of the four bits are 8, 4, 2 and 1, so this form is also called 8421 BCD or natural BCD.
It is not the same as converting the whole number to binary. Decimal 45 is 101101 in pure binary, six bits. In BCD it is 0100 0101, eight bits. BCD spends more bits but keeps every decimal digit on a nibble boundary, which makes values easy to display and keeps decimal arithmetic exact.
Decimal to BCD examples
The third line shows that leading zeros are preserved: three digits in, three groups out. The last line is how a real-time clock chip would hold the time 23:59 once the colon is removed, with hours and minutes each packed into one byte.
45 -> 0100 0101
2026 -> 0010 0000 0010 0110
007 -> 0000 0000 0111
2359 -> 0010 0011 0101 1001Input rules for this converter
The input must consist of the digits 0 to 9 and nothing else. Spaces at the start or end are trimmed. A minus sign, decimal point, thousands separator or space between digits returns the message Enter decimal digits only. To encode a value such as 12.50, convert the digit strings separately and place the sign or decimal point yourself.
The code sets no upper limit on the number of digits, so long identifiers and account numbers convert in one pass. Output groups are separated by single spaces. The tool does not add a sign nibble, so it produces plain unsigned BCD digits, not the signed packed decimal format of COBOL COMP-3 fields.
Where BCD is still used
BCD shows up wherever hardware or file formats deal in decimal digits.
- Real-time clock chips such as the DS1307 and DS3231 keep seconds, minutes and hours in BCD registers.
- Seven-segment decoder chips such as the 7447 take one BCD digit per display.
- Mainframe packed decimal fields store two BCD digits per byte for exact currency arithmetic.
- x86 processors have the DAA and DAS instructions to adjust results after BCD addition and subtraction, outside 64-bit mode.
Frequently asked questions
What is 45 in BCD?
45 in BCD is 0100 0101. The digit 4 becomes 0100 and the digit 5 becomes 0101. Compare that with pure binary, where 45 is 101101.
What is the difference between BCD and binary?
Binary converts the whole value to base 2. BCD converts each decimal digit on its own into four bits. BCD is longer but maps directly to decimal digits: 99 is 1001 1001 in BCD and 1100011 in binary.
Why are 1010 to 1111 invalid in BCD?
Four bits can hold sixteen values, but a decimal digit only needs ten. The patterns for 10 through 15 have no digit assigned, so a decoder treats them as errors. Some formats reuse them as sign or filler codes.
Can I convert negative numbers or decimals to BCD here?
Not directly. The tool accepts digits only and rejects a minus sign or decimal point. Remove them, convert the digits, and record the sign and the position of the decimal point separately, as fixed-point BCD formats do.
How do I pack the BCD output into bytes?
Join the groups two at a time. 0100 0101 becomes the byte 01000101, which is 0x45 in hex. That is why BCD bytes read like the decimal number when shown in hexadecimal. Add a leading 0 digit if the digit count is odd.
How do I turn BCD back into decimal?
Use the BCD to Decimal tool on this site, or split the bits into groups of four and read each group as one digit. 0001 1001 0100 0111 reads as 1947.