People with UE will feel that the 16-in-system display file Ash is often convenient. Why pinch? When you want to encrypt the file, transcoding, coding, jump out of a pile of 12 to look at will be big head. After all, the hexadecimal display file is brief and convenient. At least when the entrance examination of the exam card, 1+2+4+8 can calculate is a few bar. Of course, those in the exam and the college entrance examination can be 1248 yards of the wrong children's shoes, a look to know that they are decisive and procedural ape this "God left" career no ha ...
Because before trying to participate in the Popular Science innovation contest, then do the drum is to read the file into a byte stream, and into binary, four, hexadecimal string, and then the brush output to the console. Then, according to the value of each bit, the 2-color, 4-color, 16-color matrix is displayed respectively. The purpose of this is to use the camera to identify, and then revert to a byte stream to write to the file. This program is a two-egg-sore fact that crosses the product--1. Requires that files not be transferred through any media or USB device; 2.zxing and QRCode sometimes cannot find two-dimensional codes (qrcode more prone to error). You can try this topic, with the camera or speakers to send receive files, see who travels fast, the topic is really interesting.
Of course, the most important part is the transformation of the system, read the text stream byte 8 bit, with two 16 in the display. Because you may encounter byte to int as the complement of the case, so it is best to unify into positive numbers, the method is actually very simple, and the operation is done!
Copy Code code as follows:
Don't underestimate this statement, in fact, this statement is very interesting. Think about it, add a 0xff to God's horse to become a positive? 0xFF each bit is 1, that and operation is equal to no change? Hum, before someone really asked me so, if there is such a problem, it is the Java Foundation is not solid. The byte range is -128~127, not 0~255, so, like Byte b=-42, this assignment must not be in byte b= 214;
It's not hard to get this out and turn it into a n-ary string. Think carefully, is there a familiar and unfamiliar class directly with this function? Yes, it is to use an integer to achieve! But don't worry, before you use it, you have to do a little action on the Int.
Copy Code code as follows:
Know what this is about? This is +256 ah, just to see more intuitive, is the front plus one. Because you get the int into a string, it is likely that only one bit, that is, byte to 16 into the system lost one, then the whole program is not completely misplaced? To be on the safe side, let's unify it into three first.
You can try this. Look at the output of all byte-change 16
Copy Code code as follows:
public static void Main (string[] args) {
for (int i = -128; i < 128; i++) {
byte b= (byte) i;
System.out.println (integer.tostring (b & 0xff), 16));
}
}
See here, you will not think: why are you so stupid? For the int in the loop why not change to byte, not to save a line of code, how much cheaper ah! Yes, you try Bai, I will not try anyway ...
So the last code to convert byte to two-bit 16 is
Copy Code code as follows:
Integer.tostring ((bytes & 0xff) + 0x100). substring (1);
For 2, 4, 8 into the system, is a truth, I do not give an example. A code to achieve, very magical bar ...
The next step is to use the matrix lattice frame to display the file, the camera to take the recognition color, and then convert the string, and feedback a color to let the other party know that the recognition is finished to replace a picture ... So loop until the matrix lattice display file has ended. This part of the code I do not post it out, the whole process can rely on the rich imagination yy out of it ...
Then the string is reversed to the byte stream, which is simply alive
Copy Code code as follows:
(byte) Integer.parseint (String, 16)
Even the operation is not, directly out of the results, put them in the byte array, with FileOutputStream write repeatedly wrote on it! Don't forget to turn off the input and output stream ha