Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

binary
architecture
number
arithmetic

How to represent negative binary numbers

Educative Answers Team

Since computers only understand binary numbers but need to perform operations involving negative numbers, there is a way to represent negative numbers (like positive numbers) in a binary format. A negative binary number can be made from its positive version in the following two ways:

1. Sign and magnitude

This is a simple approach that adds an extra bit (i.e., sign-bit) to detect the sign of a number. 11 indicates a -ve number, ​and 00 indicates a +ve number or vice versa (depending on the architecture of the computer).

For example, if 7=(0111)7 = (0111)2 then 7=(1111)-7 = (1111)2.

A drawback is that the adders, in the underlying hardware of the computer, need to determine the sign-bit of an operation’s result. Due to this, and other disadvantages, the sign-bit representation of negative numbers is now obsolete.

2. Two’s complement

In this representation, the left-most bit is considered to be the sign-bit (without adding an extra bit), where 11 is a -ve and 00 is a +ve. This reduces the range of positive numbers that can be represented (using nn bits) from 2n12^n - 1 to 2n112^{n-1} - 1. Despite this drawback, it is now the standard way of representing negative binary numbers.

To convert a positive number into a negative number, using the two’s complement representation, invert all of the bits of the number and ​add 11.

Example

svg viewer

RELATED TAGS

binary
architecture
number
arithmetic
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring