🛠️Dev Toolbox

🔢 Number Base Converter

Convert numbers between decimal, binary, octal, and hexadecimal instantly with two's complement support.

Number Base Converter

When You Actually Need This

You're staring at a hardware datasheet that lists a configuration register as 0x3F8E and you need to flip bit 23 to enable an interrupt. You're reading a pcap dump of hex payloads. Someone pasted 0755 without specifying octal or decimal.

A base converter moves numbers between numeral systems without long division at midnight. Default covers binary (2), octal (8), decimal (10), and hexadecimal (16), supporting every integer base from 2 through 36.

The Core Concept: Positional Notation

Every numeral system is positional: digit x base^position, then sum. 325 = 3x100 + 2x10 + 5. 1011 binary = 11. A1F hex = 2591.

For bases 2 and 16: one hex digit = 4 bits. Hex to binary: expand each digit to 4 bits. Binary to hex: group bits into nibbles from the right.

Two's Complement: The Part People Get Wrong

Toggle 2's Complement when working with signed integers in embedded C, reading a raw ADC, or interpreting an int8_t that came back as 0xFF.

In 8-bit two's complement:

  • 0111 1111 (0x7F) = +127
  • 0000 0000 (0x00) = 0
  • 1111 1111 (0xFF) = -1
  • 1000 0000 (0x80) = -128

The MSB carries negative weight. To negate: flip bits, add 1. Sensor returns 0xFF + datasheet says "signed" = -1. Toggle carefully.

How to Use the Tool

Pick a source base, type or paste the value, pick a target base or "All" for every representation. Binary groups bits in nibbles for eyeballing.

Toggle 2's Complement when your value is a signed integer in 8/16/32/64-bit. Bit-width selector determines interpretation.

Real-World Examples

Parsing a register. 0b10010110 = 0x96 = 150. Bit 7 (MSB) of 10010110 = 1. Interrupt enabled.

Hex color channel. #29ABE2 -> 29, AB, E2. R=0x29 (41), G=0xAB (171), B=0xE2 (226). Use rgb(41, 171, 226) in CSS.

Octal permissions. 0755 = 111 101 101 = rwxr-xr-x. First post-0 digit is setuid/setgid/sticky; next three triplets are owner/group/other.

Signed ADC. 8-bit sensor returns 0xFF. 2s complement, bitwidth=8: -1.

Edge Cases That Catch People

  • Leading zeros: 0100 could be decimal 100, octal 64, or binary 4. Set source base explicitly.
  • Signed vs unsigned: Same hex string = two values depending on interpretation.
  • Float in binary: 0.1 decimal has no finite binary representation. That's why 0.1 + 0.2 = 0.30000000000000004.

FAQ

Q: Fractional conversion? A: 0.625 decimal = 0.101 binary. But 0.1 decimal = 0.0001100110011... (repeating). Q: Endianness? A: Out of scope. Endianness is byte-ordering. For byte-swapping, pair with a dedicated tool.

More Developer Tools

Explore our complete collection of 60+ free developer tools at dev.aisoosoo.com. All tools run 100% in your browser — no signup, no data sent to servers.