answersLogoWhite

0

In terms of storage there is no difference. A signed int is the same length (in bits) as an unsigned int. The only difference is the range of values that can be represented by those bits. With signed integers, the most-significant bit is used to denote the sign (0 = positive, 1 = negative), so an 8-bit signed char really only has 7-bits to store the value, thus limiting its positive range to [0:127] whereas the unsigned equivalent has the full 8-bits at its disposal so can represent values in the range [0:255].

Another difference is the way in which negative values are physically represented. There are in fact two ways of achieving this depending on the hardware. Older hardware generally uses ones-complement notation, which simply switches every bit. Thus 00101010 (+42) becomes 11010101 (-42). However, since the value zero is neither positive nor negative, we end up with two representations for the value zero (00000000 and 11111111). This also limits the range to [-127:127] for 8-bit signed values. Newer hardware uses twos-complement notation. To switch the sign, we first take the ones-complement as before but we then add 1 and ignore any overflow. Thus 00000000 becomes 11111111 + 1 which is 00000000. This, in turn, increases the negative range by 1, such that an 8-bit signed char now has a range of [-128:127].

Generally speaking, we use unsigned integers whenever we need to represent natural numbers, such as file sizes or array sizes; values that can never be negative. For all other work, we use signed integers.

Note that in C++ a plain char may be signed or unsigned (depending on the implementation), but is not considered the same type as either a signed or unsigned char. They are three completely independent types. Thus a plain char is only guaranteed to represent values in the range [0:127], the ASCII character codes; the only values common to both signed and unsigned char. If you specifically need to represent values outwith this range, such as [-128:127] or [0:255], use an explicitly signed or unsigned char respectively.

All other integer types (short, int, long and long long) are implicitly signed unless you explicitly declare them with the unsigned modifier. Note also that floats, doubles and long doubles are always signed (they cannot be modified).

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

What is meant by unsigned char?

AnswerAn unsigned char is a byte; its value can be between 0 and (2^8) - 1 (i.e., 0-255).


What is the difference between datatypes and modifiers in c language?

For example 'int' is a data-type, 'short', 'long', 'signed' and 'unsigned' are modifiers, 'extern', 'auto', 'static', 'register' are storage-classes. The declarations go like this: storage-class modifiers data-type identifier example: static unsigned short int x;


What are the difference between signed and unsigned data types?

A signed integer represents both positive and negative values, while an unsigned integer represents only positive values. Range depends on the number of bits the compiler assigns for the representation. bits max-negative max-positive max-unsigned 8 -128 +128 255 16 -32768 +32767 65535 32 -2147483648 +2147483647 4294967295 64 -9223372036854775808 +9223372036854775807 18446744073709551615


Is it true that in Unsigned char signed value is represented by 1 in most significant bit?

All possible values of an unsigned char are unsigned, so there is no bit that "represents a signed value." With an 8-bit byte, 1 in the most significant bit of an unsigned char represents the value 128. Consequently unsigned chars with a 1 in this position have values between 128 (when all other bits are 0) and 255 (when all other bits are 1).


What is the difference between null pointer ASCII null character and null string?

A null pointer is a pointer which does not point to any valid memory location, and usually contains the binary value "0" to represent this (this is language dependent). The ASCII null character is a character-sized zero value (in ASCII, it is an unsigned byte with a value of 0), and typically represents the end of a string (esp. as in C and C++). A null string is one that is zero characters of usable string data; in a length-based string, this means the length parameter is set to 0, and in an ASCII null-terminated string, means the first character is set to 0.

Related Questions

What is the difference between a signed and unsigned article?

A signed article identifies the writer whereas an unsigned article does not identify the author.


Which bond has the greatest ionic charcter?

A bond between elements with a large difference in electronegativity will have the greatest ionic character. For example, the bond between a metal and a nonmetal (e.g. NaCl) will have a high ionic character compared to a bond between two nonmetals (e.g. H2O).


What is the difference between unsigned and int?

The value range. Example for 16-bit integers: signed: -32768..32767 unsigned: 0..65535


Difference between signed and unsigned int?

A signed integer is one with either a plus or minus sign in front. That is it can be either positive or negative.An unsigned integer is assumed to be positive


Difference between character and string?

A string ends with a '\0' character,but character is not.


Difference between signed number from unsigned number?

a signed number is one that can be negative (have a sign) whereas an unsigned number will only be positive. due to less information, you can double the largest number storable in a signed integer to get the data available in an unsigned integer. However, PHP doesn't have unsigned integers, they're all signed.


Difference between an unsigned and a signed type?

The qualifier signed or unsigned may be applied to char or any integer. unsigned numbers are always positive or zero, and obey the laws of arithmetic modulo 2n, where n is the number of bits in the type. So, for instance, if charsare 8 bits, unsigned charvariables have values between 0 and 255, while signed charshave values between -128 and 127 (in a two's complement machine.) Whether plain charsare signed or unsigned is machine-dependent, but printable characters are always positive.


What is the difference between signed integer and unsigned integer in terms of memory and range?

Signed integer is any integer that carries negative sign while unsigned integer is any integer that carries positive sign


Why absolute value important?

The absolute value is the [unsigned] difference between two values. It tells you how far one value is from another.


What is the difference between signed integer and unsigned integer?

An unsigned integer cannot be negative. It has a maximum positive value twice that of a signed integer. Max signed: 128 Max signed: 256 I could be off by one there, though.


What is the Difference between unlocked and jailbroken?

ye ma


What is the difference between carryout and overflow?

in carry out the answer does not effect but with the overflow the answer come wrong.overflow come due to signed numbers and carry come due to unsigned.