CompTIA Tech+ (FC0-U71)IT Concepts and TerminologyMedium
A developer is writing a program that needs to store a very large integer. The programming language used defines an 'int' as a 32-bit signed integer. What is the maximum positive decimal value that can be stored in this data type?
- A65,535
- B2,147,483,647
- C4,294,967,295
- D32,767
Show answer & explanationAnswer & explanation
Correct answer: B. 2,147,483,647
For a 32-bit signed integer, one bit is used for the sign (0 for positive, 1 for negative). This leaves 31 bits to represent the magnitude. The maximum positive value is 2^31 - 1, which equals 2,147,483,647.
Why the other options are wrong
- A. This is the maximum value for a 16-bit unsigned integer (2^16 - 1).
- C. This is the maximum value for a 32-bit unsigned integer (2^32 - 1).
- D. This is the maximum positive value for a 16-bit signed integer (2^15 - 1).
Signed Integer Range
The range of positive and negative values that can be represented by a fixed number of bits, where one bit is reserved for the sign.
- One bit is for the sign (0 for positive, 1 for negative).
- Remaining bits represent the magnitude.
- Range: -(2^(n-1)) to (2^(n-1) - 1) for n bits.
Memory trick: Sign takes one bit, magnitude gets the rest, maximum is 2 to the power, then subtract one, for the best!