Reputation: 4250
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
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:
Upvotes: 5
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
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
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