I am learning about Java and I have the code as below:
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
try (DataOutputStream testFile = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("test_file.txt")))) {
testFile.writeInt(4);
}
}
}
The code above would write the number 4 as binary into the byte stream then appending it to the text_file.txt but when I checked the writeInt() method of the DataOutputStream class, it is shown as:
public final void writeInt(int v) throws IOException {
out.write((v >>> 24) & 0xFF);
out.write((v >>> 16) & 0xFF);
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
incCount(4);
}
I did some research about >>> and & from here and here but still I can not figure out what the code above really doing under the hood
Can someone elaborate more for me on this ?
Kind regards,
Ken