English tools / Electronics

Number base converter

Convert between binary, decimal and hex, with the ASCII character and byte order. Also turns text into ASCII or UTF-8 codes and back.

Binary, decimal and hex

Bit width (pick 8 to 64 bits to enter negative numbers as two’s complement)

Text and ASCII codes

Code format

Wrong result or a typo? Send feedback

How to convert between binary, decimal and hex

Each binary digit, counted from the right, is worth 1, 2, 4, 8, 16, 32, 64, 128 and so on. Add up the places that hold a 1 to get the decimal value: 0100 0001 = 64 + 1 = 65.

To go from decimal to binary, subtract the largest power of two that fits and repeat: 65 = 64 + 1, so bits 7 and 1 are set and the rest are 0.

Hex uses 0–9 and A–F for 0 to 15, which is exactly four binary digits. Split the binary into groups of four from the right and replace each group with one hex digit: 0100 0001 → 4, 1 → 0x41. That’s why firmware and datasheets write register values in hex.

DecimalBinaryHexDecimalBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

Negative numbers and two’s complement

Computers store negative numbers in two’s complement: invert every bit of the positive number and add 1. In 8 bits, -1 is 1111 1111 (0xFF) and -128 is 1000 0000 (0x80). The same bits read as 255 unsigned or -1 signed, depending on how the program declares them.

Once you pick a bit width in the tool above, you can type a negative decimal number, and the result lists the signed value. The range of each width:

BitsUnsignedSignedC type
80 to 255-128 to 127uint8_t / int8_t
160 to 65,535-32,768 to 32,767uint16_t / int16_t
320 to 4,294,967,295-2,147,483,648 to 2,147,483,647uint32_t / int32_t
640 to about 1.8 × 10¹⁹about ±9.2 × 10¹⁸uint64_t / int64_t

ASCII table

ASCII uses 0 to 127 for English letters, digits, punctuation and control characters. 0 to 31 and 127 are control characters such as LF (line feed, 0x0A), CR (carriage return, 0x0D) and ESC (0x1B); 32 is the space (SP). A few patterns worth remembering: digits 0–9 are 0x30–0x39, uppercase A is 0x41, lowercase a is 0x61, and the two cases differ by exactly 0x20.

DecHexCharDecHexCharDecHexCharDecHexChar
000NUL3220SP6440@9660`
101SOH3321!6541A9761a
202STX3422"6642B9862b
303ETX3523#6743C9963c
404EOT3624$6844D10064d
505ENQ3725%6945E10165e
606ACK3826&7046F10266f
707BEL3927'7147G10367g
808BS4028(7248H10468h
909HT4129)7349I10569i
100ALF422A*744AJ1066Aj
110BVT432B+754BK1076Bk
120CFF442C,764CL1086Cl
130DCR452D-774DM1096Dm
140ESO462E.784EN1106En
150FSI472F/794FO1116Fo
1610DLE483008050P11270p
1711DC1493118151Q11371q
1812DC2503228252R11472r
1913DC3513338353S11573s
2014DC4523448454T11674t
2115NAK533558555U11775u
2216SYN543668656V11876v
2317ETB553778757W11977w
2418CAN563888858X12078x
2519EM573998959Y12179y
261ASUB583A:905AZ1227Az
271BESC593B;915B[1237B{
281CFS603C<925C\1247C|
291DGS613D=935D]1257D}
301ERS623E>945E^1267E~
311FUS633F?955F_1277FDEL

FAQ

What does 0x mean in front of a hex number?

It only marks the number as hex and isn’t part of the value: 0x41, 41h and $41 are the same number. C, Python and JavaScript use 0x; assembly often uses an h suffix. Binary is often written with 0b. The tool accepts numbers with or without these prefixes.

What’s the difference between big-endian and little-endian?

When a multi-byte number is stored in memory or sent over a wire, big-endian puts the most significant byte first and little-endian puts the least significant byte first. 0x12345678 is 12 34 56 78 in big-endian and 78 56 34 12 in little-endian. ARM Cortex-M and x86 are little-endian; network protocols and many sensor registers are big-endian. If the bytes on a logic analyzer or UART look reversed, this is usually why.

Can Chinese or accented characters be converted to ASCII?

No. ASCII only has 128 characters. Web pages and most software now use UTF-8, where ASCII characters stay one byte and other characters take 2 to 4 bytes: é is C3 A9 and 你 is E4 BD A0. The tool converts text as UTF-8.

Why is the ASCII code of the digit 0 equal to 48?

ASCII puts the digits 0–9 at 0x30–0x39. A '7' received over UART is the byte 0x37; subtract 0x30 (or '0') to get the number 7. Forgetting this is a common firmware bug.