**Integer data type ‘short int’ and value range**

In this article, let’s study the integer data types ‘short int’ and value range in C.

**Integer data type: ****short int and unsigned short int**

- Variable of type short int is used to store 2 bytes of signed data.
- Variable of type unsigned short int is used to store 2 bytes of unsigned data.
- You can just mention short(for signed) or unsigned short. “int” will be assumed.
- Short type variable always consumes 2 bytes of memory irrespective of compilers.

**Range calculation of short int:**

For example, represent the data -25 in 2 byte signed data representation. Here the data is negative.

First, take the binary representation, which is a pure binary representation of 25 in 2 byte data representation. That will be this one 0000000000011001.

And after that, take the 1’s complement. 11111111111100110 is a 1’s complement format of 25, where you have to convert all ones into zeros and zeros into ones.

After that, let’s take 2’s complement of that. For that, you have to add 1 to 1’s complement format; you get 2’s complement format. 1111111111100111 is the 2’s complement format of -25.

Here, the 15th bit, that is the last bit, the most significant bit will be 1 to indicate the data is negative, and the rest of the bits will be used to store the 2’s complement format of the magnitude, that is 25.

The hex value of -25 will be 0xFFE7. So, that is the 2 byte signed data representation of -25 (Figure 3).

Now represent the data +25 in 2 bytes signed data representation in hex form. So, that will be 0x0019 in hex.

**Range calculation of short int**

- Short range: -32,768 to 32,767
- Unsigned short range: 0 to 65535.

Because for unsigned data representation in 2 bytes, you have all the 16 bits to represent the magnitude. So, there is no sign bit. That’s why all 16 bits will be used to store the magnitude. So, the least value will be 0, and the highest value will be 65535, which is nothing but 0xFFFF in hex.

In the following article, let’s understand int and unsigned int.

**FastBit Embedded Brain Academy Courses**

Click here: https://fastbitlab.com/course1