What is the maximum value for a UInt32?
Is there a way I can use the sizeof operator to get the maximum value (as it is unsigned)? So I don't end up with #defines or magic numbers in my code.
Remarks. The value of this constant is 4,294,967,295; that is, hexadecimal 0xFFFFFFFF.
The number 4,294,967,295, equivalent to the hexadecimal value FFFF,FFFF16, is the maximum value for a 32-bit unsigned integer in computing.
long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
There's a macro UINT32_MAX
defined in stdint.h
which you can use
#include <stdint.h>
uint32_t max = UINT32_MAX;
<stdint.h>
:http://pubs.opengroup.org/onlinepubs/009695299/basedefs/stdint.h.html
The maximum value for UInt32 is 0xFFFFFFFF
(or 4294967295 in decimal).
sizeof(UInt32)
would not return the maximum value; it would return 4, the size in bytes of a 32 bit unsigned integer.
Just set the max using standard hexadecimal notation and then check it against whatever you need. 32-bits is 8 hexadecimals bytes, so it'd be like this:
let myMax: UInt32 = 0xFFFFFFFF
if myOtherNumber > myMax {
// resolve problem
}
The portable way:
std::numeric_limits<uint32_t>::max()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With