You are on page 1of 4

Definition:

A signed integer or signed character is a data type in computer programming that can represent both
positive and negative values. The "signed" keyword is used to indicate that the data type can hold
negative numbers in addition to positive numbers.

The "unsigned" keyword is used to indicate that a data type in computer


programming represents only non-negative values (zero or positive values).

The difference between signed character, short, and long integers

The differences between signed char, signed short int (often referred to as short),
and signed long int (often referred to as long) lie in their memory size and the
range of values they can represent:
1. signed char: It is a data type used to represent signed characters or small
signed integers. Typically, signed char uses 1 byte (8 bits) to store values.
It can represent signed integer values from approximately -128 to 127.
2. signed short int (short): It is a data type used to represent signed integers
with a smaller range compared to signed long int. Typically, short uses 2
bytes (16 bits) to store values. This results in a range of values from
approximately -32,768 to 32,767.
3. signed long int (long): It is a data type used to represent signed integers
with a larger range compared to signed short int. Typically, long uses 4
bytes (32 bits) to store values. This provides a wider range of values
from approximately -2 billion to 2 billio

The range values of signed character :


In the C programming language, the values of signed char typically range from
-128 to 127. The signed char type uses one byte (8 bits) to represent integer
values, where the most significant bit (MSB) is used as the sign bit.
The range of values for signed char is derived from the fact that one bit is
reserved for the sign, leaving 7 bits for the magnitude. The sign bit is set to 0
for positive values and 1 for negative values. By using the remaining 7
bits, signed char can represent values from -2^7 (-128) to 2^7-1 (127).

Why do we use the only one bye to represent signed character:

The use of 8 bits (1 byte) for representing signed char values is a convention in
the C programming language. Here are a few reasons why 8 bits are
commonly used:

1. Historical Reasons
2. Compact Representation
3. Memory Efficiency

In the C programming language, the values of signed short int typically


range from -32,768 to 32,767.
The signed short int type, also known as short or short int, uses two bytes (16
bits) to represent integer values. The most significant bit (MSB) is used as the
sign bit, similar to signed char.
By using 15 bits for the magnitude and reserving 1 bit for the sign, signed short
int can represent values from -2^15 (-32,768) to 2^15-1 (32,767).

Why do we use the only one bye to represent signed character:


The use of 16 bits (2 bytes) for representing signed short int values is a
convention in the C programming language. Here are a few reasons why 16
bits are commonly used:
1. Range of Values:.
2. Memory Efficiency
3. Common Data Size

handling The range values of long signed integer :

In the C programming language, the values of signed long int can vary
depending on the specific platform and implementation. However, the C
standard guarantees that a signed long int will have a minimum range of -
2,147,483,647 to 2,147,483,647.
The signed long int type uses four bytes (32 bits) to represent integer values.
The most significant bit (MSB) is used as the sign bit, similar to signed
char and signed short int.
By using 31 bits for the magnitude and reserving 1 bit for the sign, signed long
int can represent values from -2^31 (-2,147,483,648) to 2^31-1
(2,147,483,647).

The choice of 32 bits (4 bytes) for representing signed long int values in the C
programming language is primarily driven by the need for larger integer
ranges and compatibility with existing systems. Here are a few reasons for
using 32 bits:
1. Larger Range:
2. Common Word Size:
3. Compatibility and Interoperability:
4. Balance between Range and Memory Efficiency

The overall summarisation table:


Size/Type Range
8 bit signed -128 to 127
16 bit signed -32,768 to 32,767
32 bit signed -2,147,483,648 to 2,147,483,647

Formula to use:

Range = (-(2^(n-1))) to (2^(n-1) - 1)

Ex: let's consider a signed integer type represented using 8 bits ( n = 8):
Range = (-(2^(8-1))) to (2^(8-1) - 1)
= (-128) to (127)

n this case, the range of values that can be represented by an 8-bit signed
integer is from -128 to 127, inclusive.
It's worth noting that the range is asymmetrical because one of the possible
values is used to represent zero. The negative range extends one more value
towards the negative end to account for the inclusion of zero. part of
subtracting 1 from the positive end of the range ensures that the highest
positive value falls within the range while still accounting for the inclusion of
zero and the negative values.

You might also like