Look at the Integer class. It has methods to convert int values to different Strings for displaying.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
it seems the way around and I'm not sure whether the result is what I need.
Can you show what the code outputs and explain what is wrong with it and give an example of what you want to print?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Without the full data, I can not explain what you are seeing.
S.o.p(Integer.toBinaryString( (int) arrayOfBytes[1]))
What does arrayOfBytes[1] contain? It looks like it has an int value of 10
S.o.p(getHexString(arrayOfBytes))
What is arrayOfBytes here? What does the getHexString() method do? What does it take for an argument?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Can you answer my questions? Or change your code to have all the data be in the program. Remove reading data from a file. Hardcode the data in the program so there is no questions about what is in the file.
What does arrayOfBytes[1] contain? It looks like it has an int value of 10
What is arrayOfBytes here? use Arrays.toString() to format the content of the array and print it
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Your code is missing the import statements.
When I execute it with a '2' as input I get:
java.lang.ArrayIndexOutOfBoundsException: 1
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
What is the problem with your program? Does it read the bytes from the file correctly?
Get a hexeditor look at the bytes in the file and compare them to what your program reads.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Look at the indexes you are using on line 7 and line 8
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
So when I save one symbol to file, the file's content in binary format is just ASCII codes of that symbol and line feed symbol. Is that true?
Probably.
You should get a hex editor and look at the contents of a text file to see the values of the bytes in the file in hex.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Question Answered as of 1 Year Ago by
NormR1