In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, the sign bit is a
bit
The bit is the most basic unit of information in computing and digital communication. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented as ...
in a
signed number representation
In computing, signed number representations are required to encode negative numbers in binary number systems.
In mathematics, negative numbers in any base are represented by prefixing them with a minus sign ("−"). However, in RAM or CPU reg ...
that indicates the
sign
A sign is an object, quality, event, or entity whose presence or occurrence indicates the probable presence or occurrence of something else. A natural sign bears a causal relation to its object—for instance, thunder is a sign of storm, or me ...
of a number. Although only
signed numeric data types have a sign bit, it is invariably located in the
most significant bit
In computing, bit numbering is the convention used to identify the bit positions in a binary numeral system, binary number.
Bit significance and indexing
In computing, the least significant bit (LSb) is the bit position in a Binary numeral sy ...
position,
so the term may be used interchangeably with "most significant bit" in some contexts.
Almost always, if the sign bit is 0, the number is non-negative (positive or zero).
If the sign bit is 1 then the number is negative. Formats other than
two's complement
Two's complement is the most common method of representing signed (positive, negative, and zero) integers on computers, and more generally, fixed point binary values. Two's complement uses the binary digit with the ''greatest'' value as the ''s ...
integers allow a
signed zero
Signed zero is zero with an associated sign. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0 and 0 are equivalent. However, in computing, some number representations allow for the existence of two zeros, often denoted by ...
: distinct "positive zero" and "negative zero" representations, the latter of which does not correspond to the mathematical concept of a
negative number
In mathematics, a negative number is the opposite (mathematics), opposite of a positive real number. Equivalently, a negative number is a real number that is inequality (mathematics), less than 0, zero. Negative numbers are often used to represe ...
.
When using a complement representation, to convert a signed number to a wider format the additional bits must be filled with copies of the sign bit in order to preserve its numerical value,
a process called ''
sign extension'' or ''sign propagation''.
Sign bit weight in Two's complement
Two's complement
Two's complement is the most common method of representing signed (positive, negative, and zero) integers on computers, and more generally, fixed point binary values. Two's complement uses the binary digit with the ''greatest'' value as the ''s ...
is by far the most common format for signed integers. In Two's complement, the sign bit has the weight where w is equal to the bits position in the number.
With an 8-bit integer, the sign bit would have the value of , or -128. Due to this value being larger than all the other bits combined, having this bit set would ultimately make the number negative, thus changing the sign.
Sign bit weight in Ones' complement
Ones' complement
The ones' complement of a binary number is the value obtained by inverting (flipping) all the bits in the Binary number, binary representation of the number. The name "ones' complement" refers to the fact that such an inverted value, if added t ...
is similar to Two's Complement, but the sign bit has the weight where w is equal to the bits position in the number. With an 8-bit integer, the sign bit would have a value of , or -127. This allows for
two types of zero: positive and negative, which is not possible with Two's complement.
Sign bit in sign magnitude integers
Using
sign magnitude, the sign bit directly determines the sign. If the sign bit is 0, the number is positive; if the sign bit is 1, the number is negative.
Similarly with Ones' Complement, this allows for both a positive and a negative zero.
Sign bit in floating-point numbers
Floating-point
In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
numbers, such as
IEEE format,
IBM format,
VAX format, and even the format used by the Zuse
Z1 and
Z3 use a
Sign and magnitude representation.
References
Binary arithmetic
Computer arithmetic
Sign (mathematics)
{{Comp-sci-stub