Study Notes on char length in java and c/c ++
In the past two days, I am helping you change an encryption program. The following is the core code of c ++:
Char cpass [5]; for (int j = 0; j <instring. length (); j ++) {cpass [j] ^ = npwd ;}
However, a problem may occur when writing data to java. At first glance, the conversion can be basically unblocked, but the result is problematic.
It is a char type problem found by searching online materials. In fact, this involves comparing the data types in c/c ++ with those in java.
First, the char type.
The char type in c/c ++ is 8-bit
The char type in java is 16-bit
Therefore, when processing this type of conversion using java, you should pay attention to clearing the 8-bit high of the char type, which is easy to match with the 0x00ff bit. The completed java program is as follows:
Char cpass [5]; for (int j = 0; j <instring. length (); j ++) {cpass [j] ^ = npwd; cpass [j] & = 0x00ff; // clear the 8-bit high}