Language
English English Vietnamese (Tiếng Việt) Vietnamese (Tiếng Việt) Chinese (简体中文) Chinese (简体中文) Portuguese (Brazil) (Português do Brasil) Portuguese (Brazil) (Português do Brasil) Spanish (Español) Spanish (Español) Indonesian (Bahasa Indonesia) Indonesian (Bahasa Indonesia)
Binary to Hexadecimal

Binary to Hexadecimal

Encode a bit pattern the way an assembler would: nibble split, byte-paired hex output and a 0x literal on the clipboard for your source file.

Packing Bits into Opcode Bytes

Assembly manuals describe an instruction as a field diagram: so many bits for the opcode, a bit for the direction flag, two more for the addressing mode. Assemblers, disassemblers and hex editors then show you the finished byte in base-16. This page closes that gap — write the bit pattern you worked out on paper and get the hex byte a listing would print.

Four bits make one hex digit: split the string into nibbles from the right and translate each one. 11010110 splits into 1101 and 0110, which is D6.

Who Needs the Byte Back in Hex

Hand-Assembling an Instruction

Retro and microcontroller projects still get patched byte by byte; the encoding table gives you bits, the monitor program wants hex.

Computer Architecture Labs

Coursework asks you to encode an instruction from a field layout and then compare it with what the assembler produced in the object dump.

The same route serves anyone building a value out of flags — a checksum byte, a status word, a bit-packed configuration field — where the design happens in bits and the artefact ships in hex.

From Bit String to Hex Byte

1

Pad the pattern to whole bytes

Write the leading zeros yourself if your field layout is shorter than eight bits. Six bits alone would produce a single-digit answer, which reads badly next to real machine code.

2

Read the hex as byte pairs

The lower field spaces its digits in twos, so each pair you see is one byte of the encoding — the same grouping an object dump uses.

3

Take it with the 0x marker

Copying the hex field hands you 0x plus the digits and drops the display spaces, which is exactly the literal a C or Rust source file wants.

Working backwards: paste a byte into the hex field to see its bit layout above. To land on the dedicated hex-first page instead, press swap and your value travels with you.

Bit Patterns Behind x86 Opcode Bytes

Single-byte x86 opcodes are a good way to sanity-check your bit reading, because the mnemonic is unambiguous and every debugger prints the same value. Encode the pattern, compare with the byte below, and you know your nibble split is right.

Bit patternHex bytex86 instruction
0101010155PUSH the base pointer — the classic prologue byte
1001000090NOP, the byte used to pad and to blank out code
11000011C3RET, the near return that ends most functions
11001100CCINT3, the software breakpoint a debugger writes in
11101011EBJMP with a one-byte signed displacement
11110100F4HLT, which parks the processor until an interrupt

Output Spaced as Bytes

Hex digits appear in pairs, so a multi-byte encoding lines up with the columns of a disassembly listing.

Upper-Case Digits Throughout

Letters always come back as A to F, matching the convention most assemblers and hardware manuals print.

Long Encodings Stay Exact

Bit strings past fifteen characters switch to big-integer arithmetic, so a 64-bit immediate keeps every digit intact.

Machine Code Questions

My field layout is 12 bits — where do the missing bits go?

Nibbles are counted from the right, so a 12-bit string produces three hex digits and nothing is lost. If the hardware stores that field inside a 16-bit word, type the four extra zeros on the left yourself to get the four-digit form.

Why did my leading zeros disappear from the answer?

The result is the plain value, so 00001111 comes back as F rather than 0F. Add the zero in front when you write the byte down; the number is identical either way.

Does this tell me the byte order in memory?

No. You get the numeric value of the pattern. Whether a multi-byte word is stored low byte first is a property of the processor, so a little-endian machine will show those bytes reversed in a memory dump.

Can I encode a negative displacement this way?

Only if you do the two's complement step first. Work out the bit pattern for the negative value at your chosen width, then convert that pattern — the minus sign itself is not accepted in the input.

Why is hex the standard for machine code rather than octal?

Modern hardware is organised in eight-bit bytes, and eight divides evenly into two nibbles. Octal digits cover three bits, which straddles byte boundaries — that suited the 12-bit and 36-bit machines of the 1960s, not today's.

01
0b
0123456789ABCDEFabcdef
0x

Single-Byte Opcodes

01010101 = 55
10010000 = 90
11000011 = C3
11001100 = CC
11101011 = EB
11110100 = F4

Binary (Base-2)

The layer an encoding table describes: opcode bits, mode bits and flag bits laid out one position at a time.

Hexadecimal (Base-16)

How the finished instruction is published — two digits per byte in listings, patch notes and hex editors.

Pad the pattern to eight bits before reading the byte
11010110 splits into 1101 0110 = D6
Hex output is spaced in pairs, one pair per byte
Copying the hex field prefixes it with 0x for source code
Want to learn more? Read documentation →
1/5
Start typing to search...
Searching...
No results found
Try searching with different keywords