# Negative number encoder

## World's simplest binary tool

Free online negative number encoder. Just load your negative integers and they will automatically get encoded to binary. It supports one's complement, two's complement, excess binary, sign bit, and base -2 representations. There are no ads, popups or nonsense, just an awesome negative binary encoder. Load negative values – get encoded binaries. Created for developers by developers from team Browserling.

we're on twitter!
tweet tweet

Love what we do? You can follow us on Twitter for updates!

A link to this tool, including input, options and all chained tools.

Can't convert.

Negative number encoder tool
What is a negative number encoder?

This tool converts negative decimal numbers (and also positive) to the binary numeral system. The binary number system has only two symbols '0' and '1', and unlike the decimal number system, there is no negative sign '-'. Therefore, negative numbers in binary are represented in special binary schemes that encode the minus sign to a bit pattern. We have implemented five different signed number representations. The first one is the signed bit method. It's the simplest way to encode a signed integer to binary. In this method, the most significant bit (leftmost bit) is used as the sign of the number. If the integer is positive, then the leftmost bit is set to '0'. If the number is negative, then the leftmost bit is set to '1'. You can think of '0' as '+' and '1' as '-'. The remaining bits show the absolute value of the number. For example, 01011101b is a positive number because the first bit is '0' and the remaining bits are 1011101b, which is equal to 93 in decimal, therefore this number is +93. A negative -93 would be 11011101b. As you can see, the first bit is flipped from 0 to 1 and that also flips the sign of the number. The second method of representation is one's complement. The positive numbers in this method are the same as in the sign bit method but the negative numbers are created by applying the bitwise not operation to positive numbers. This operation replaces all zeros with ones and all ones with zeros. For example, if we have the number 93, which is 01011101b in binary, then after bitwise not this number becomes 10100010b, which is negative -93. The third encoding method is two's complement. This method is the dominant encoding scheme in computer hardware as it's easier to perform mathematical operations with it. In two's complement, a negative number is add-one its bitwise not. What this means is first we flip all bits in the number and then increment the number by one. To get -93 from 93, which is 01011101b, we first find its bitwise-not, which is 10100010b, and then add one. The number becomes 10100011b, which is -93. Another representation method is biased binary, also known as excess (offset) binary code. It uses a novel approach to encode negatives. In excess code, the number (-2)

^{n}is defined to be 0b and it can represent numbers from (-2)^{n}to 2^{n}-1. The number (-2)^{n}+1 is 1b, (-2)^{n}+2 is 10b, (-2)^{n}+3 is 11b, and so on (you're counting up from (-2)^{n}). If you want to find -93, then you first find the smallest n, such that this number fits in (-2)^{n}. In this case, it's 7 because (-2)^{7}is -128. Then you define (-2)^{7}to be 00000000b, and now you count up: -128 is 00000000b, -127 is 00000001b, -126 is 00000010b, -125 is 00000011b, …, until you reach -93. In this case, -93 is 00100011b. If you keep counting up, you'll also find 93, which is 11011101b, and 127, which will be all one-bits 11111111b. Yet another encoding method is base minus two, also known as the negabinary method, which decomposes a number into a sum of powers of -2. For example, the number -94 is the sum 1×(-2)⁷ + 1×(-2)⁶ + 1×(-2)⁵ + 0×(-2)⁴ + 0×(-2)³ + 1×(-2)² + 1×(-2)¹ + 0×(-2)⁰ and from the coefficients before the -2 powers we find that -94 is 11100110b. In the same way, the number 94 is 1×(-2)⁸ + 1×(-2)⁷ + 0×(-2)⁶ + 1×(-2)⁵ + 0×(-2)⁴ + 0×(-2)³ + 0×(-2)² + 1×(-2)¹ + 0×(-2)⁰, which is 110100010b in base -2. The last method is a bonus method as it doesn't change the binary value in any way and only adds a minus '-' sign before negative binaries. We named it the human method because it makes it easy to distinguish between positive and negative binary numbers. This utility also allows you to customize the binary number format – you can add padding of any length and append a binary prefix or suffix to the output number. Simple and easy!
Negative number encoder examples
Click to use

Two's Complement

This example converts ten negative integers into a binary representation using the two's complement algorithm. This algorithm finds the binary values of the corresponding positive integers, calculates their inverse (by complementing 1's and 0's), and adds +1 to the result. Applying this algorithm, for example, to the number -9, we get 9 = 1001b, inverted 0110b, add +1 = 0111b = -9.

-1
-2
-3
-4
-5
-6
-7
-8
-9
-10

1
10
01
100
011
010
001
1000
0111
0110

**Required options**

Add padding to encoded binary.

One's Complement

This example applies the one's complement algorithm to four negative numbers. It first finds the binary code of positive numbers and then complements all bits. This example also uses padding and the algorithm also complements the padding bits. In this case, the padding is 8, so the first number -5 is converted to the positive number 5 as 101, then full padding is added as 00000101, and now, the digits are inverted – 1's become 0's and 0's become 1's. The resulting number 11111010 is the number -5 in one's complement scheme. The output is also formatted with the "0b" prefix that says that it's a binary base number.

-5
-20
-30
-40

0b11111010
0b11101011
0b11100001
0b11010111

**Required options**

Add padding to encoded binary.

Sign Bit Representation

In this example, we enter both positive and negative integers in the input. We run the sign bit algorithm and as you can see, signed and unsigned numbers have the same binary values with the exception of the first bit – in negative integers, the most significant bit is 1 but in positive integers, it's 0. This is why this encoding scheme is called the sign bit representation – the first bit always tells the number's sign and the remaining bits tell the magnitude of the number. We have also added the "B" postfix and set padding to eight positions. Note that the padding doesn't include the sign bit.

32
16
8
4
2
1
-1
-2
-4
-8
-16
-32

00100000B
00010000B
00001000B
00000100B
00000010B
00000001B
100000001B
100000010B
100000100B
100001000B
100010000B
100100000B

**Required options**

Add padding to encoded binary.

Offset Binary

In this example, we convert three pairs of positive and negative numbers to the offset binary encoding. When encoding positive numbers, it finds the regular binary representation of the number and adds a 1 at the beginning, which indicates a plus sign. When encoding a negative number, this method acts a little bit differently. First, it converts the unsigned number to a binary base, then it calculates its inverse, then it increments the result by one (similar to two's complement method), and then it adds a 0 at the beginning, which indicates the minus sign.

2
-2
5
-5
7
-7

1000010₂
0111110₂
1000101₂
0111011₂
1000111₂
0111001₂

**Required options**

Add padding to encoded binary.

Base -2 Representation

This example converts two numbers (9 and -9) from a base 10 to a negative base -2. To convert a number to a new base, it's first decomposed as a sum of powers of the new base and then the coefficients before each power term represent the number in this new base. With the base -2, the number is decomposed into a sum of powers of -2 and for the decimal number 9, we have the following result: 9₁₀ = 1×(-2)⁴ + 1×(-2)³ + 0×(-2)² + 0×(-2)¹ + 1×(-2)⁰ = 11001₂. For the negative number -9, we have the following: -9₁₀ = 1×(-2)³ + 0×(-2)² + 1×(-2)¹ + 1×(-2)⁰ = 1011₂.

9
-9

11001
1011

**Required options**

Add padding to encoded binary.

Human Representation

This example demonstrates the human method of representing negative binary numbers. We, humans, can simply add a - sign in front of the number, just like we do for regular decimal numbers, and that's what we do here. For example, the number 123 is 1111011 in binary and the number -123 is simply -1111011. We also add an uppercase binary prefix "0B" to the results so that everyone knew it was a binary number.

-123
-126060
-369088
-50505

-0B1111011
-0B11110110001101100
-0B1011010000111000000
-0B1100010101001001

**Required options**

Add padding to encoded binary.

Pro tips
Master online binary tools

You can pass input to this tool via

__?input__query argument and it will automatically compute output. Here's how to type it in your browser's address bar. Click to try!
https://onlinebinarytools.com/encode-negative-binary

__?input__=-1%0A-2%0A-3%0A-4%0A-5%0A-6%0A-7%0A-8%0A-9%0A-10&representation=twos-complement&padding-length=0&prefix=without-prefix
All binary tools

Quickly convert ASCII characters to binary numbers.

Quickly convert binary numbers to ASCII characters.

Quickly convert UTF8 characters to binary bits.

Quickly convert binary bits to UTF8 characters.

Quickly generate random binary values.

Quickly create an image from a binary number.

Quickly convert binary numbers to octal numbers.

Quickly convert octal numbers to binary numbers.

Quickly convert binary numbers to decimal numbers.

Quickly convert decimal numbers to binary numbers.

Quickly convert binary numbers to hexadecimal numbers.

Quickly convert hexadecimal numbers to binary numbers.

Quickly convert octal values to BCD values.

Quickly convert BCD values to octal values.

Quickly convert decimal values to BCD values.

Quickly convert BCD values to decimal values.

Quickly convert hex values to BCD values.

Quickly convert BCD values to hex values.

Quickly convert an IP address to a binary IP address.

Quickly convert a binary IP address to a human readable IP.

Quickly convert an IPv6 address to a binary IPv6 address.

Quickly convert a binary IPv6 address to a human readable IPv6.

Quickly convert a string to binary values.

Quickly convert binary values to a string.

Quickly convert binary numbers to reflected binary numbers.

Quickly convert reflected binary numbers to binary numbers.

Quickly convert octal numbers to reflected binary numbers.

Quickly convert reflected binary numbers to octal numbers.

Quickly convert decimal numbers to reflected binary numbers.

Quickly convert reflected binary numbers to decimal numbers.

Quickly convert hexadecimal numbers to Gray code.

Quickly convert Gray code to hexadecimal numbers.

Quickly calculate the sum of a bunch of binary values.

Quickly calculate the difference of a bunch of binary values.

Quickly calculate the product of a bunch of binary values.

Quickly convert a negative number to a binary representation.

Quickly convert a negative binary number to a decimal number.

Quickly convert base 2 numbers to base -2.

Quickly calculate bitwise AND of a bunch of binary values.

Quickly calculate bitwise NAND of a bunch of binary values.

Quickly calculate bitwise OR of a bunch of binary values.

Quickly calculate bitwise NOR of a bunch of binary values.

Quickly calculate bitwise XOR of a bunch of binary values.

Quickly calculate bitwise XNOR of a bunch of binary values.

Quickly calculate bitwise NOT of a bunch of binary values.

Quickly invert bits of binary numbers.

Quickly reverse the order of bits in binary numbers.

Quickly convert plain text to binary values.

Quickly convert binary numbers to plain text.

Quickly randomize the order of bits in binary numbers.

Quickly rotate bits in binary numbers to the left or right.

Quickly shift bits of a binary number to the left.

Quickly shift bits of a binary number to the right.

Coming soon
These binary tools are on the way

Create a File from Binary Values

Convert binary numbers to a binary file.

Binary Dump a File

Create a binary dump of files in your browser.

Convert Binary to Arbitrary Base

Convert binary values to any base (up to base 64).

Convert Binary to Roman Number

Convert binary numbers to Roman numerals.

Convert Roman Number to Binary

Convert Roman numerals to binary values.

Binary Sheffer Stroke

Calculate bitwise sheffer stroke operator of binary values.

Convert Binary to BCD

Encode every binary bit as a binary coded decimal.

Convert BCD to Binary

Decode binary coded decimals to binary bits.

Divide Binary Numbers

Perform division operation on several binary numbers.

Rotate a Binary Right

Rotate bits of a binary number to the right.

Rotate a Binary Left

Rotate bits of a binary number to the left.

Extract Bits from Binary Numbers

Extract n-th bit from a binary number.

Count Number of Zeroes

Count number of 0 bits in a binary number.

Count Number of Ones

Count number of 1 bits in a binary number.

Calculate Parity

Count parity of a binary number.

Convert EBCDIC to Binary

Convert EBCDIC characters to binary values.

Convert Binary to EBCDIC

Convert binary bits to EBCDIC symbols.

Swap Binary Endianness

Change endianness of a binary number.

Convert Little Endian Binary to Big Endian Binary

Convert a binary number from little endian to big endian.

Convert Big Endian Binary to Little Endian Binary

Convert a binary number from big endian to little endian.

Convert a Floating Point Number to Binary

Find the binary representation of a floating point number.

Convert Binary Values to a Bitmap

Convert a binary string to a bitmap image.

Convert a Bitmap to Binary Numbers

Convert a bitmap image to zeros and ones.

Subscribe!
Never miss an update

Cool!

Notifications
We'll let you know when we add this tool

Cool!