This is a creation in Article, where the information may have evolved or changed.
here is actually mainly translated http://blog.golang.org/constants, which An exercise:the largest unsigned int section.
how to construct the largest unsigned number. For an unsigned number that determines the number of bits, as long as the shift is possible, for example: for UInt32, as long as const MAXUINT32 = 1<<32-1.
However, for a uint with an indeterminate number of bits, this is not the case, in fact, we know that the largest number of unsigned and 1 bits is the same. However, either the const maxuint UINT =-1//Error:negative value , or the const maxuint UINT = UINT ( -1)//Er Ror:negative value
, can not be compiled, the reason is naturally the type and scope of the conflict. But at runtime, the value of 1 can indeed be passed to unsigned yes, how to compile and pass this value to the unsigned number? OK
var u uint
var v =-1
U = UINT (v)
So it's done. Another method is to reverse 0. The difference is that after 0 inverse, is infinitely more than 1, then a finite range of uint to pick it up, obviously will be the compiler think of the loss of precision. The method is to construct a definite number of bits 0, and then reverse, as follows:
Const MAXUINT = ^uint (0)
Here are two ways to get the maximum number of unsigned numbers.