Hex Binary Calculator: conversions, bitwise, two's complement

Convert numbers between bases 2, 8, 10, 16, perform binary arithmetic and bitwise AND/OR/XOR/NOT, shifts and two's complement. Four programming modes.

Calculation parameters
Was this calculator useful?

Numeral systems: decimal, binary, octal, hexadecimal

Each positional system represents a number as sum of powers of the base: n = Σᵢ dᵢ·b^i, where dᵢ is the i-th digit (0 ≤ dᵢ < b) and b the base. Most used in computing: base 10 (decimal, digits 0-9); base 2 (binary, digits 0-1, fundamental for electronic circuits); base 8 (octal, digits 0-7, historically in PDP-11 Unix); base 16 (hex, digits 0-9, A-F). Hexadecimal is preferred to represent bytes (1 byte = 2 hex digits) in memory addresses, RGB colors, MAC addresses, hashes.

Conversion methods

From base b to decimal: sum dᵢ·b^i. Example: hex A3 = 10·16 + 3·1 = 163. From decimal to base b: successive divisions by b, read remainders in reverse. Example: 163 / 16 = 10 remainder 3, 10 / 16 = 0 remainder 10 (A) → A3 hex. Binary to hex: group bits in nibbles (4 bits) from right: 10110010₂ = 1011 0010 = B2₁₆. Vice versa: each hex digit → 4 bits.

Binary arithmetic

Addition: rules 0+0=0, 0+1=1, 1+1=10 (carry). Example: 1011 + 0110 = 10001 (11+6=17). Subtraction: as in decimal with borrow, or sum with two's complement of subtrahend. Binary multiplication: shift-and-add. Division: shift-and-subtract. Modern CPUs implement these in hardware at 1 clock cycle per 64-bit (x86-64, ARM64).

Bitwise operations

AND (&): 1 iff both bits are 1. Used for masking: x & 0x0F isolates low 4 bits. OR (|): 1 if at least one. Used to set bits: x | 0x80 sets MSB. XOR (^): 1 if different. Used for flipping and simple crypto: x ^ key. NOT (~): inverts all bits. Shift left (<<): multiply by 2^n. Shift right (>>): divide by 2^n (arithmetic keeps sign, logical fills with 0). Example: 0b1010 << 2 = 0b101000 = 40; 0b1010 >> 1 = 0b101 = 5.

Two's complement

Standard representation of negative integers in almost all modern CPUs. For N bits the range is [−2^(N−1), 2^(N−1) − 1]. To negate: invert all bits and add 1. Example 8-bit: +5 = 00000101; −5 = 11111011 (invert 11111010, +1). MSB is the sign bit. Advantages: unified add/sub (no special case); unique zero (positive); simple sign extension. Used in int32, int64 of all modern languages.

Decimal ↔ hex mapping

0-9: same digits. 10=A, 11=B, 12=C, 13=D, 14=E, 15=F. Notable: 255 = FF (8-bit max), 256 = 100, 4095 = FFF (12-bit), 65535 = FFFF (16-bit), 16777215 = FFFFFF (24-bit RGB color), 2147483647 = 7FFFFFFF (INT32_MAX), 4294967295 = FFFFFFFF (UINT32_MAX). Web colors: #FF0000 red, #00FF00 green, #0000FF blue, #FFFFFF white, #000000 black.

Practical applications

Low-level programming (microcontrollers, embedded, drivers); CPU register and I/O peripheral manipulation; cryptography (XOR cipher, AES S-box); encoding/decoding (Base64, UTF-8); graphics (#RRGGBB hex colors, GPU shaders); networking (hex IP addresses, subnet masks); operating systems (virtual memory, page tables); debugging (memory dumps, hex editors); certifications (CCNA, LPIC, OCP); competitive programming (bitmask DP, XOR tricks, Gray code).

How to use

Select mode: Conversion (number + source base + target base → value), Arithmetic (two binary/hex numbers → sum, subtraction, product), Bitwise (two numbers → AND, OR, XOR, NOT, shift), Two's complement (signed integer + bit width → hex/binary representation). Supported bases: 2, 8, 10, 16.

Positional systems and why hexadecimal in computing

Every positional numeral system represents a number as a sum of digits times powers of the base: n = Σ dᵢ·bⁱ. The decimal system (base 10) is the human one, but computers use binary (base 2) because transistors have only two stable states, on and off, representable as 0 and 1. Binary is verbose, though: the number 255 needs eight digits, 11111111. This is where hexadecimal (base 16, digits 0-9 and A-F) comes in: since 16 = 2⁴, each hex digit corresponds exactly to 4 bits (a nibble) and two digits to a byte. So 11111111 becomes the compact FF. This is why memory addresses, web colour codes (#RRGGBB) and data dumps are written in hex. The octal system (base 8) was widely used in early computers and survives in Unix permissions (chmod 755).

Two's complement and bitwise operations

Negative numbers in computers are represented with two's complement: to negate, invert all bits and add 1. With n bits you cover values from −2ⁿ⁻¹ to 2ⁿ⁻¹−1: for 8 bits the range is [−128, 127], and the most significant bit (MSB) acts as the sign. This universally adopted scheme has two decisive advantages: there is a single zero (avoiding the "−0" of sign-magnitude) and addition works uniformly for positive and negative numbers, greatly simplifying arithmetic circuits. Bitwise operations manipulate individual bits: AND extracts masks, OR sets bits, XOR toggles or compares them, NOT inverts them, and shifts multiply or divide by powers of 2. They underlie flags, permission masks, cryptography and low-level optimisations.

Updated July 2026

Frequently Asked Questions

What is the hexadecimal system?

Hexadecimal is a base-16 numeral system using digits 0-9 and letters A-F (where A=10, B=11, ..., F=15). It is used in computing because each digit represents exactly 4 bits, making binary numbers compact to write: the byte 11111111 becomes FF.

How do you convert binary to hexadecimal?

Group the bits in fours starting from the right and translate each group into a hex digit. For example 1011 0110 becomes B6, because 1011 = B (11) and 0110 = 6. The method works because 16 = 2⁴, so each 4-bit nibble corresponds to one hex digit.

Why do computers use binary?

Because electronic circuits rely on transistors with only two stable states: on and off, high and low voltage. These two states are naturally represented by 0 and 1, the digits of the binary system. All information — numbers, text, images — is encoded as sequences of bits.

What is two's complement?

It is the standard method to represent negative integers in computers. To negate a number, invert all its bits and add 1. With n bits you represent values from −2ⁿ⁻¹ to 2ⁿ⁻¹−1: for 8 bits, from −128 to 127. The most significant bit indicates the sign.

Why use two's complement instead of sign-magnitude?

Because it has two advantages: there is a single representation of zero (sign-magnitude has both +0 and −0) and addition works identically for positive and negative numbers, with no special subtraction circuits. This greatly simplifies the arithmetic hardware of processors.

What are bitwise operations used for?

Bitwise operations manipulate the individual bits of a number: AND applies masks (isolates bits), OR sets bits to 1, XOR toggles or compares them, NOT inverts them, shifts multiply or divide by powers of 2. They are used for flags, permissions, graphics, cryptography and low-level optimisations.

What is a nibble and what is a byte?

A nibble is a group of 4 bits, representable by a single hex digit (0 to F). A byte consists of 8 bits, i.e. two nibbles, written with two hex digits (00 to FF). A byte can take 256 distinct values and is the basic unit of computer memory.

Comments (0)

No comments yet. Be the first!