golang integer constant INT_MAX INT_MIN Max Min (reproduced)

Original Address: https://blog.csdn.net/bdss58/article/details/78388858

In C, there are some standard libraries limits.h defines a constant maximum and minimum values, for example an int constant INT_MAX maximum, minimum constant INT_MIN, unsigned integer type uint constant maximum UINT_MAX

golang standard library does not define these variables. However, bit manipulation operations can easily define these constants.

Uint Unsigned integer
whose minimum value is 0, all bits in its binary representation is 0,

uint = 0 UINT_MIN const
1
all bits of the binary representation of the maximum value is 1, then

uint UINT_MAX ^ = const (0)
1
signed integer int
according complement, its maximum binary representation, the first 0 and the other 1, then,

INT_MAX = int const (^ uint (0) >> 1)
1
according to the complement, which is the minimum binary representation, the first one, the rest 0, then

const INT_MIN = ^INT_MAX

Author: bdss58
Source: CSDN
Original: https://blog.csdn.net/bdss58/article/details/78388858
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!

发布了12 篇原创文章 · 获赞 0 · 访问量 3055

Guess you like

Origin blog.csdn.net/weixin_42268466/article/details/83476134