Skip to content
ohmplay. Electronics
laboratory

Home / Tools / Binary, decimal and hexadecimal

Experiment 006 / Digital logic

Binary, decimal and hexadecimal

Convert numbers exactly and build a value by toggling bits.

Workbench / Ideal model ● In your browser
01 / Adjust the inputs

From 0 to 18,446,744,073,709,551,615.
No 0x/0b prefixes or separators.

Try an example
02 / Build a number BigInt · exact integers
Decimal · base 10 42
Binary · base 2 101010
Hexadecimal · base 16 2A

Turn on a bit to add its weight. The most significant bit appears first; leading zeros do not change the value.

42 = 32 + 8 + 2 = 2⁵ + 2³ + 2¹.
0010 1010 → 2 A in hexadecimal.

Use it in your classroom

Share this exercise with its current values. The link contains only numbers and model options; do not add names or email addresses.

The code includes a text link to the full explanation outside the frame. Animation starts paused. Adjust the iframe height if your platform needs it.

The same 42, three representations

Decimal 42 is written as 101010 in binary and 2A in hexadecimal. Binary weights 32, 8 and 2 are on. Adding them gives 42.

To convert binary to hexadecimal, group bits into blocks of four from the right. Leading zeros preserve the value: 0010 1010 becomes 2 A. Hexadecimal A means ten, so 2A = 2 × 16 + 10 = 42.

Each position has a weight

Value = Σ digitᵢ × baseⁱ
Binary: weights 1, 2, 4, 8, 16, 32…
Hexadecimal: weights 1, 16, 256, 4096…

Positions start at zero on the right. The tool shows each nonzero digit’s contribution and a table of successive divisions: divide the decimal value by the target base, keep the remainder and repeat with the quotient. Read the remainders in reverse order.

Bit buttons show their position and weight; their accessible names include the full decimal weight. Changing the input base preserves the number, and toggling bits updates every representation.

64-bit unsigned integers, without rounding

The range is 0 to 18,446,744,073,709,551,615 inclusive: 2⁶⁴ − 1. BigInt provides exact integer arithmetic, avoiding the precision loss of ordinary JavaScript numbers beyond 2⁵³ − 1.

Negative numbers, fractions, scientific notation, separators and prefixes such as 0x or 0b are not accepted. Visible width does not alter or truncate the number; it expands to the next available size if needed. This is not two’s complement or floating-point representation.

Common mistakes

  • Assuming 10 means the same number in every base: it means two in binary and sixteen in hexadecimal.
  • Counting the first bit as position 1: the rightmost bit is 2⁰.
  • Interpreting F as fifteen positions: it is one digit with the value 15.
  • Converting 64-bit integers with a numeric type that rounds large values.

Try it yourself

What is 1111 0000 in decimal and hexadecimal?

128 + 64 + 32 + 16 = 240. Groups 1111 and 0000 are F and 0: F0.

What happens if only bit 63 is on?

The value is 9,223,372,036,854,775,808. It is positive in this unsigned converter and is not interpreted as a negative number.