GoLanguage is used in my work. Look at the open source http/request.go.
The following code was found
const (
defaultMaxMemory = 32 << 20 // 32 MB
)
This 32M is really a force lattice. First of all, I will briefly introduce that "moving left is equivalent to multiplying 2, and moving left 20 is equivalent to multiplying 20 powers by 2."
Here's a skill you need to install 13, which is to recite the power table of the commonly used 2.
7 128
8 256
10 1024 1K
16 65536 64K
20 1048576 1MB
30 1073741824 1GB
40 1099511627776 1TB
At the very least, we should know how many powers 1K 1M 1G 1T is 2 each.
Bit Operational Basis
Bit-by-bit & like what we write for judgment & true is true, and here it's all one and only one.
Bit-by-bit | similar to what we write in terms of judgement | as long as one result is true, and here it is as long as one result is 1.
The difference of XOR ^ is 1, otherwise it is 0.
Reverse 0 to 1, 1 to 0
Left shift is used to move all the binary bits of a number left by several bits, so it is equivalent to multiplying by 2, but the left shift is much faster than multiplication. (Refer to C Programming Edition 3, page 323, Tan Haoqiang)
Right shift is used to move all binary bits of a number to the right by several bits. It depends on the computer system whether the left high bit of unsigned number is complemented by 0 or the left high bit of signed number is complemented by 0 or 1.
Bit Operations Application Tips
The number of zeroes to be used with, a location available or
If you want to take the reverse and exchange, use XOR easily.
Application of Bit Operations
1. BitMask is used in NS_OPTIONS in iOS.
In UIView.h, you can see a @property (nonatomic) UIView Autoresizing autoresizing Mask; UIView Autoresizing is defined as follows
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
Look at the definition of UIView Animation Transition above
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
};
The former is a bit mask implementation, which can be combined freely, such as
autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
Represents the upper right margin automatically adjusted.
Cancel top adjustment
autoresizingMask = autoresizingMask &~ UIViewAutoresizingFlexibleTopMargin
Determine whether the right side is automatically adjusted
if (autoresizingMask & UIViewAutoresizingFlexibleRightMargin) == UIViewAutoresizingFlexibleRightMargin
2. How do UI designers get 10-digit colors by giving them 16-digit colors, such as 0xff0000?
We usually say that RGB color is 24 bits, that is, R, G, B occupy 8 bits respectively.
#define mRGBToColor(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0]
(rgb & 0xFF0000) You can move 16 bits to the right because one color occupies 8 bits, so R has to move two 8 bits, that is 16 bits.
3. Judging odd and even I & 1 = 1 odd I & 1 = 0 even
4, to be continued