Hi,
Is there any way to read a binary file into n-bit array?
There is a file that I want read which consists of 10-bit unsigned integers
I want to read them into an int arrray. Is there any way for this?
Thanx
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi,
Is there any way to read a binary file into n-bit array?
There is a file that I want read which consists of 10-bit unsigned integers
I want to read them into an int arrray. Is there any way for this?
Thanx
There's not 'bit' datatype in Java. Hence, if you really want to use bits, you'll have to use bytes or booleans or chars or String or something (though booleans' size is 1 byte (or even bigger, I've heard once that it depends on the JVM implementation...)).
To do what you want you can use the following algorithm:
1. Read all the bytes from the file into an array
2. Define a function that would take a byte and return it's bits in a chosen format. Btw, consider Integer.toBinaryString(), which takes an integer and returns a string with it's bits.
3. Apply the (2) function to (1) array in order to represent bits of the file in memory
4. Parse (3) datastructure in a way that corresponds your needs
i dont know if its just me but i have found it hard to work with unsigned integers in java
Is it so difficult, for example, to create a separate class to deal with that data type?