Two bytes are merged into a 16-bit short type

1. For example, combine two char types into one short type

Idea: as shown in the following code

unsigned short func = 0;

func = func | data[7];
func = func << 8;
func = func | data[8];

As shown in the code above, first OR the low eight bits of temp with st[1], and then the eighth bit of temp is st[1]. After shifting temp to the left by 8 bits, the eighth bit is shifted to the high eight bits. Go, so that the lower eight bits of temp are all 0s, and the OR operation with st[0], so that temp contains the string "10", from the lower eight bits "1" to the upper eight bits "0" , Two bytes of content.
Original: https://blog.csdn.net/zlx_code/article/details/77456155 
 

Guess you like

Origin blog.csdn.net/xiaolei251990/article/details/84848717