How Convert Binary to Negabinary Works
Convert Binary to Negabinary transforms signed or two's complement binary integers into base -2 (negabinary) positional notation, which represents both positive and negative integers uniquely without a sign bit.
Binary arithmetic and base-2 encoding form the physical foundation of digital microprocessors, network packets, memory buffers, and cryptographic primitives. Every calculation in this utility runs directly inside your browser using exact JavaScript BigInt and typed-array pipelines, so arbitrary-length bitstreams, 128-bit addresses, and raw byte buffers never suffer from 53-bit IEEE floating-point truncation or server latency.
Repeated Euclidean Division by -2
While n != 0: rem = n mod (-2); n = trunc(n / -2) if rem < 0: rem += 2; n += 1 prepend rem
Because powers of -2 alternate signs (+1, -2, +4, -8, +16, -32, ...), every integer in Z has one unique finite representation using only digits 0 and 1.
Worked Reference Examples
| Input | Output | Step / Bit Note |
|---|---|---|
| 1010 (10) | 11110 | 16 - 8 + 4 - 2 = 10 |
| -1 (-1) | 11 | -2 + 1 = -1 |
| -1010 (-10) | 1010 | -8 + 0 - 2 + 0 = -10 |
Practical Engineering Applications
Sign-Free Computer Arithmetic
Study alternative positional systems (used in experimental Polish computers like SKRZAT and BINEG).
Algorithmic & Olympiad Math
Verify base -2 solutions in competitive programming and Knuth TAOCP exercises.
Precision, Edge Cases & Best Practices
Switch Input Interpretation to Two's Complement if pasting fixed-width signed binary words where MSB=1 is negative.
All input parsing strips harmless formatting whitespace, underscores, or common prefixes such as 0b where applicable, while preserving exact bit order and padding width so outputs drop straight into C/C++, Rust, Verilog, VHDL, Python, and embedded firmware test harnesses.