Reputation: 2540
I am studying beginner cryptography in C++ and was taking a look inside limits.h.
Would someone please explain to me what this code snippet does? Does it define the number of binary numbers these types can hold? Specificaly, what is 0xffu?
Sorry, for the crap title.
Upvotes: 0
Views: 3167
Reputation: 866
0xffu is the number 255 in hexadecimal notation, defined as being interpreted as unsigned for the compiler.
these_MAX defines mean that this is the max value a datatype can hold before an overflow happens.
i.e.
unsigned char myChar = 0xFFu;
myChar += 1;
printf("%i", myChar);
will print
0
Same for the other unsigned datatypes here.
Maybe your question can be understood as "What happens if I change this?". No, it does not define the maximum number, it is a help for you as programmer have the maximum numbers at hand for programming. If you change this snippet, it will not change the datatypes. Just some algorithms using these defines will change their behavior (working with another max value).
I do not recommend changing these, if that was your intent.
Upvotes: 2
Reputation: 916
These just define the largest values that can be stored in each of unsigned char
, unsigned short
, unsigned int
, and unsigned long int
. 0xffU
means hexadecimal value FF
, with the U
suffix denoting that that literal is explicitly unsigned.
Upvotes: 2
Reputation: 38
It defines it's maximal numeric value it can store.
So unsigned char can store 2^8-1.
Upvotes: 1
Reputation: 129454
The U
is used to indicate unsigned
constants. Without it, you may get warnings such as "value outside of range for int
".
Upvotes: 1