ForHosting KIT · Unit converters

BCD converter

42 in 8421 BCD is 0100 0010: each decimal digit gets its own group of four bits, unlike pure binary. Convert numbers for clocks, displays and logic labs, or decode them back. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Value to convert
42
Conversion direction
To bcd
You get
Decimal
42
Decimal string
42
Bcd
01000010
Bcd spaced
0100 0010

This BCD converter maps a non-negative decimal integer to packed 8421 binary-coded decimal bit strings, and decodes valid BCD nibbles back to base-ten. Binary-coded decimal is the classic digital encoding in which each decimal digit occupies its own four-bit group with place weights eight, four, two, and one—so nine becomes one-zero-zero-one, five becomes zero-one-zero-one, and forty-two becomes zero-one-zero-zero followed by zero-zero-one-zero. Unlike pure binary, BCD preserves decimal digit boundaries, which is why it still appears in real-time clocks, industrial displays, calculators, and teaching labs. The engine is fully deterministic: it either builds exact nibble patterns or rejects illegal codes such as one-zero-one-zero through one-one-one-one, never calls the network, never samples randomness, and never depends on the clock.

What 8421 BCD means and what you get back

Binary-coded decimal, in the natural 8421 form used here, assigns every decimal digit from zero through nine a four-bit pattern whose bit weights are eight, four, two, and one from left to right. Digit zero is zero-zero-zero-zero, one is zero-zero-zero-one, five is zero-one-zero-one, and nine is one-zero-zero-one. Multi-digit numbers simply concatenate those nibbles in the same order as the decimal digits: two hundred fifty-five becomes the three nibbles for two, five, and five.

This is different from converting the whole value to pure binary; pure binary would encode two hundred fifty-five as eight ones, while BCD keeps three separate digit groups so humans and decimal hardware can read each place independently. Empty values, negative numbers, fractions, non-binary characters in a BCD string, and bit lengths that are not multiples of four are also rejected.

Where BCD conversion fits in study, hardware, and software

Students meet binary-coded decimal when a digital-logic course introduces seven-segment displays, when a computer-architecture lab maps register dumps to human-readable decimals, or when an exam asks whether a four-bit pattern is a legal BCD digit. Teachers can pre-generate answer keys for modest digit lengths without trusting opaque calculator apps that silently accept codes above nine or mix pure binary with BCD. Embedded and industrial engineers check RTC chips, BCD counters, PLC displays, and protocol fields that still store each decimal place as a nibble.

Developers call the same contract from scripts to seed deterministic test vectors for parsers, to validate user-entered BCD strings in configuration UIs, or to satisfy programming-challenge statements that demand packed 8421 rather than a hand-waved sketch. Product and education tools use the conversion when a learner types a decimal value and the UI must show both the compact bit string and the spaced nibble view immediately.

Pair it with binary-to-decimal or hex converters when you are building a small lab of free, deterministic number-format tools for digital literacy and firmware debugging.

Homework and digital-logic drills

Encode textbook decimals into 8421 nibbles and verify which four-bit patterns are legal BCD before submitting lab answers.

Firmware and RTC dumps

Decode packed BCD fields from real-time clocks, counters, and display drivers into clear decimal values for debugging.

What does the BCD converter cost?

It is free in your browser on this page.

What is 8421 BCD?

Each decimal digit 0–9 is stored as a 4-bit nibble with bit weights 8, 4, 2, and 1. Multi-digit numbers concatenate those nibbles in digit order.

Can I convert pure binary with this tool?

No. This tool only maps decimal digits to 8421 BCD nibbles and back. Use a binary-to-decimal converter for pure base-2 place values.

How is 42 written in BCD?

As 0100 0010. Each decimal digit gets its own group of four bits: the 4 becomes 0100 and the 2 becomes 0010, written in the same order as the digits.

Why are some four-bit patterns rejected?

A BCD group can only hold a decimal digit from zero to nine. Patterns worth ten to fifteen do not stand for any single digit, so they are rejected instead of being turned into a nearby number.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/fmt/bcd

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/fmt/bcd \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":"42","direction":"to_bcd"}'
{
  "value": "42",
  "direction": "to_bcd"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "fmt.bcd",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_digits15
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

What 8421 BCD means and what the response contains

When you choose direction to_bcd, the calculator returns the normalized decimal integer and decimal_string, a compact bcd bit string with no separators, a bcd_spaced string with a space between nibbles, the nibbles array, the digits array, nibble_count, bit_length, a method tag 8421_bcd, the encoding label 8421, and a short formula reminder. When you choose from_bcd, the same shape is returned after decoding, with direction set to from_bcd. There is no approximate path and no silent coercion of illegal patterns into nearby digits: any nibble whose integer value is ten or higher is rejected with invalid_input because those codes are not valid 8421 decimal digits.

How value and direction are read and how results stay reproducible

Each nibble is decoded with the 8421 weights and must land in zero through nine; a nibble such as one-zero-one-zero is reported as an invalid BCD nibble with its position so students and engineers can find the bad code in a dump. Encoding walks each decimal digit and emits its four-bit pattern; decoding joins the recovered digits and strips leading zeros while preserving a lone zero. The preferred fields are value for the payload and direction for the conversion sense, but aliases input, text, n, number, bits, bcd, and decimal are accepted for the payload, and dir, mode, and convert for the direction, so spreadsheets, query strings, and typed forms can reuse the same contract. Direction accepts to_bcd and decimal_to_bcd for encoding, and from_bcd and bcd_to_decimal for decoding; spelling is case-insensitive and hyphens may replace underscores. For to_bcd, value must be a non-negative whole number given as a digit string or finite integer—no minus signs, no decimal points, no scientific notation, and no more than fifteen digits after stripping leading zeros. For from_bcd, value must be a bit string of zeros and ones whose length is a positive multiple of four; outer whitespace is trimmed, an optional zero-b prefix is stripped, and spaces, underscores, or hyphens between bits or nibbles are ignored so strings such as zero-one-zero-zero space zero-zero-one-zero parse the same as the compact form. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing 8421 tables yourself.

Where BCD conversion fits in study, hardware, and software

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result.

Deterministic test fixtures

Generate reproducible BCD bit strings and decimal echoes for unit tests, property checks, and CI assertions.

What happens on an invalid BCD nibble?

Any nibble whose value is 10–15 (patterns 1010 through 1111) is rejected with invalid_input. Only 0000–1001 are valid 8421 digits.

Are negative numbers or fractions supported?

No. Only non-negative whole numbers up to fifteen digits are accepted for to_bcd, and packed bit strings for from_bcd.

Read the full KIT documentation →