Sign bit
Template:Refimprove In computer science, the sign bit is a bit in a signed number representation that indicates the sign of a number. Although only signed numeric data types have a sign bit, it is invariably located in the most significant bit position,[1] 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).[1] If the sign bit is 1 then the number is negative. Formats other than two's complement integers allow a signed zero: distinct "positive zero" and "negative zero" representations, the latter of which does not correspond to the mathematical concept of a negative number.
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,[2]Template:Rp a process called sign extension or sign propagation.[3]
Sign bit weight in Two's complement
| Bits | Value using Two's complement |
|---|---|
| <templatestyles src="Mono/styles.css" />0000 | 0 |
| <templatestyles src="Mono/styles.css" />0001 | 1 |
| <templatestyles src="Mono/styles.css" />0111 | 7 |
| <templatestyles src="Mono/styles.css" />1000 | −8 |
| <templatestyles src="Mono/styles.css" />1001 | −7 |
| <templatestyles src="Mono/styles.css" />1111 | −1 |
Two's complement is by far the most common format for signed integers. In Two's complement, the sign bit has the weight -2w-1Script error: No such module "Check for unknown parameters". where w is equal to the bits position in the number.[1] With an 8-bit integer, the sign bit would have the value of -28-1Script error: No such module "Check for unknown parameters"., 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
| Bits | Value using One's complement |
|---|---|
| <templatestyles src="Mono/styles.css" />0000 | 0 |
| <templatestyles src="Mono/styles.css" />0001 | 1 |
| <templatestyles src="Mono/styles.css" />0111 | 7 |
| <templatestyles src="Mono/styles.css" />1000 | −7 |
| <templatestyles src="Mono/styles.css" />1001 | −6 |
| <templatestyles src="Mono/styles.css" />1111 | −0 |
Ones' complement is similar to Two's Complement, but the sign bit has the weight -(2w-1 +1)Script error: No such module "Check for unknown parameters". where w is equal to the bits position in the number.Template:Fact With an 8-bit integer, the sign bit would have a value of -(28-1 +1)Script error: No such module "Check for unknown parameters"., 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
| Bits | Value using sign magnitude |
|---|---|
| <templatestyles src="Mono/styles.css" />0000 | 0 |
| <templatestyles src="Mono/styles.css" />0001 | 1 |
| <templatestyles src="Mono/styles.css" />0111 | 7 |
| <templatestyles src="Mono/styles.css" />1000 | −0 |
| <templatestyles src="Mono/styles.css" />1001 | −1 |
| <templatestyles src="Mono/styles.css" />1111 | −7 |
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.[2]Template:Rp Similarly with Ones' Complement, this allows for both a positive and a negative zero.
Sign bit in floating-point numbers
Floating-point 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.Template:Fact
References
<templatestyles src="Reflist/styles.css" />
Script error: No such module "Check for unknown parameters".