Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
can java read bits?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Moerderin, post: 574689"] In terms of reading and storing, binary information is managed by bytes. Thank you Frank, and everyone else. You are helping me understand this a great deal. first of all I feel like an idiot, after looking at other posts and so forth I realize I am supposed to label my bits like this : | 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Well, with all of your guys' help that you gave me I tried writing code to do pretty much exactly what I need, but the mask isn't working. here is the exact situation of what I have: | 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ----------------------------------------------------------------- | Word Count | word 1 ----------------------------------------------------------------- | 0 | 1 | Message_ID | unused | word 2 ----------------------------------------------------------------- | stuff I don't care about here | word 3 -----------------------------------------------------------------| more stuff I don't care about here | word 4 ----------------------------------------------------------------- My goal in writing this code was to extract the Message_ID and put it in its own file. to do that I wrote code to skip the first word (which is two bytes) and read the second word after shifting the Message_ID to the far right (at least thats what I thought the coding would do :) Again, thank you for all your guys' help well here is the short java file that I wrote, its not long so please look at it and tell me why it wont mask and shift the Message_ID and write it into a new file import java.io.*; public class Mask { public static void main(String[] arguments) { try { // create object to be read File bits = new File("c:/test.txt"); FileInputStream file = new FileInputStream(bits); //skip the first two bytes file.skip(2); //read the next two bytes byte[] ary = new byte[2]; //read file that contains bits file.read(ary); //create a mask int i = 0; int messageIDBits = (i >> 6) & 0xFF; //create object to write the bits which were read File txt = new File("c:/test1.txt"); FileOutputStream messageID = new FileOutputStream(txt); //write the bits containing the Message_ID messageID.write(ary); //close the files file.close(); messageID.close(); } catch (Exception e) { System.out.println("Error -- " + e.toString()); } } } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
can java read bits?
Top