Text & code / Guides

Binary, hexadecimal and decimal: is your input a number or text?

A sequence of digits can name a number or spell the byte values of a text message. Decide which interpretation you have before converting.

The integer stays the same

Decimal 65, binary 1000001 and hexadecimal 41 are three notations for one nonnegative integer. The base changes how the value is written, not what it counts. Enter 65 into the decimal-to-binary converter and then compare the hexadecimal tool’s result. A leading zero may be added to display a complete eight-bit byte, giving 01000001, but that display choice does not change the integer. Binary-to-decimal can reverse the numeric notation. This workflow makes sense for an identifier, bit mask or count known to be an integer.

Text first needs a character encoding

The letter A is a text character. UTF-8 represents it with the single byte 0x41, whose bit pattern is 01000001. That happens to match the integer example above because ASCII characters occupy those byte values in UTF-8. But the string “65” contains two characters, 6 and 5; its UTF-8 bytes are 0x36 and 0x35. Running a number converter on 65 and a text-to-bytes converter on “65” therefore answers different questions. Check whether the source means a numeric value or literal typed characters.

The same digits can refer to different things.
  1. Integer 65₁₀ = 41₁₆ = 1000001₂
  2. Text “A” → UTF-8 byte 41₁₆
  3. Text “65” → UTF-8 bytes 36 35₁₆

Accented text exposes the distinction

The character é is represented in UTF-8 by two bytes, C3 A9 in hexadecimal. Its Unicode code point is U+00E9, and it may also be expressed by e followed by a combining accent in a different normalized form. A text-to-binary tool may show two eight-bit groups for the composed UTF-8 form, rather than one eight-bit group for one visible letter. Treating the character’s code point as if it were a single byte would lose information or produce the wrong output. Use the UTF-8 byte view when troubleshooting a text protocol, not the decimal-to-hex integer tool.

Watch boundaries and separators

The binary string 0100000101000010 can be read as two bytes, 01000001 and 01000010, which spell AB under UTF-8. Without a known character encoding and grouping rule, a bare bit string is ambiguous. Decimal 4142 is not the same value as hexadecimal 4142, and neither automatically means two text bytes. Prefixes such as 0x for hexadecimal and explicit spaces between bytes make a record easier to read. Before decoding pasted data, preserve its original delimiters and find out whether leading zeros are significant in the surrounding format.

Choose a repeatable check

For numeric conversions, record the original integer and its base, convert it, then reverse it with the matching numeric tool. For text, record the characters, their normalization if relevant and their UTF-8 bytes, then decode the bytes with the matching text tool. Try A, 65 and é as three separate test inputs. If a copied output looks surprisingly long, count bytes and inspect whether the input contained spaces, a newline or non-ASCII characters. The two workflows can meet at a byte value, but their interpretation comes from the source contract.

Try the converter

Convert the integer 65 to binary, then compare text-to-bytes.

Convert a whole decimal integer into base-two digits without a size limit.

Open full converter

More guides

Conversion guides

Explore guides