[Solved] For a 16-bit integer variable, can you assign the variable with an integer value of 72368?


You can try, but if the assignment succeeds it will not store the entirety of your original number, because representing it with accuracy requires more than 16 bits.

The highest order bit in a 16 bit integer is the 215 place. Two to the fifteenth power is 32768. Setting your 16 bits to all ones will yield 65535 (32768 * 2 – 1), if the integer is unsigned, so that’s the highest number you can assign reliably.

In any case, this is easy enough to test:

#include <stdio.h>

int main(void) {
  unsigned short i = 72368;
  printf("%d\n", i); // 6832
  return 0;
}

Note that 72368 is interpreted as an int, and an implicit conversion occurs to unsigned short, although the compiler will warn you. Try it online.

4

solved For a 16-bit integer variable, can you assign the variable with an integer value of 72368?