Shash
Shash

Reputation: 4250

How is sign bit represented in a 32 bit machine

Lets say I work in a 32 bit machine. With reference to MSB (most significant bit) which is the sign bit, my question is how is it represented for this archietecture.

My understanding is that every byte has a sign value. So if this is the case then there would be four signed bits. Am I correct or missing something here. Thanks!

Upvotes: 1

Views: 820

Answers (4)

Jon
Jon

Reputation: 437386

Bytes are groups of bits. They don't have any inherent meaning, and neither do the bits that make them up. Meaning is only given if you e.g. choose to interpret these four bytes as a signed integer, and then the bits mean what they mean because the platform designers say so.

In practically all prevalent architectures, integers are represented using two's complement. This means that:

  1. There's only one sign bit for the whole value (not for every byte), but this is a de facto condition, simply because the platform designers chose to use two's complement -- not because there's something special about all MSBs in the universe.
  2. There's no sign bit at all for unsigned values (obviously).

Upvotes: 5

user529758
user529758

Reputation:

If you're wrking with signed integers, then the compiler treats groups of bytes as an entire number, and that group has one sign bit. In C terminoligy: when you use int16_t, two bytes have one sign bit. For int32_t, four bytes have one. For signed char, each signed char (=byte) has a sign bit.

Upvotes: 0

Thom Smith
Thom Smith

Reputation: 14086

The specific representation of integers in C is not specified by the standard. However, in practice, most (virtually all?) machines will use two's complement representation for negative numbers. Two's complement does not have a sign bit, per se, but the most significant bit of the integer will be 1 for negative numbers and 0 for nonnegative numbers,

Upvotes: 3

strnk
strnk

Reputation: 2063

On most architecture your 32-bits signed integers are stored in two's complement : there is only one "sign bit" (which is not really one strictly speaking).

Upvotes: 0

Related Questions