ProgrammingModerateTCS NQT · Wipro
What is the range of values of a signed 8-bit two's-complement integer?
- A. -127 to 127
- B. -128 to 128
- C. -128 to 127
- D. 0 to 255
Correct answer: C. -128 to 127
8 bits give 256 patterns. Two's complement assigns one more pattern to the negatives because zero takes a non-negative slot: −2^7 to 2^7 − 1. '−127 to 127' is the sign-magnitude or ones'-complement range.
More C Programming questions
- What is printed? c unsigned x = 8; if (x & (x - 1) == 0) puts("pow2"); else puts("not");
- What is printed? c int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, r[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)…
- What is printed? c const char s = "banana", p = s; int c = 0; while ((p = strchr(p, 'a')) != NULL) { c++; p++; } printf("%d", c);
- Assume IEEE-754 double. What is printed? c printf("%d %d", 0.1 + 0.2 == 0.3, 0.5 + 0.25 == 0.75);
- Assume 4-byte int. What is printed? c printf("%d %d", sizeof(int) -1 < 0, (int)sizeof(int) -1 < 0);
- What is printed? c Bool b = 0.5; printf("%d %d", b + 2, (Bool)256);