public class BinaryEncoding
extends java.lang.Object
The bytes in the binary encoding are read/written with a linear scan
Remark: this class requires at least Java 1.7
Constructor and Description |
---|
BinaryEncoding()
Warning: this method is not supported
|
BinaryEncoding(int b)
Create a binary encoding of a given size
|
BinaryEncoding(java.lang.String filename)
Read the binary encoding from file
|
Modifier and Type | Method and Description |
---|---|
void |
appendNextFloat(float x)
Append to the encoding a float number on 32 bits (4 bytes)
|
void |
appendNextInteger(int v)
Append to the encoding an integer on 32 bits (4 bytes)
|
void |
appendNextWord(byte[] word)
Append to the encoding the next 4 bytes (a memory word, on 32 bits)
|
static int |
fromByteArray(byte[] bytes)
Decode an array of four bytes to the corresponding integer value (on 32 bits)
|
int |
getByteCounter()
Return the byte counter: the number of bytes already read/written during the linear scan of the encoding
|
int |
getNextBit()
Read the next 4 bytes and return the corresponding integer value
|
float |
getNextFloat()
Read the next 4 bytes and return the corresponding float value
|
int |
getNextInteger()
Read the next 4 bytes and return the corresponding integer value
|
byte[] |
getNextWord()
Read the next 4 bytes (a memory word, on 32 bits)
|
int |
readBitInByte(byte b,
int i)
Read the i-th in the byte
|
byte |
setBitInByte(byte b,
int i)
Set the i-th in the byte to '1'
|
static byte[] |
toByteArray(int value)
Encode an integer value (on 32 bits) as four bytes
|
void |
writeToFile(java.lang.String filename)
Write the whole encoding to a binary file
|
public BinaryEncoding()
public BinaryEncoding(int b)
b
- the size of the encoding (number of bytes)public BinaryEncoding(java.lang.String filename) throws java.io.IOException
filename
- name of the input filejava.io.IOException
public void writeToFile(java.lang.String filename) throws java.io.IOException
filename
- name of the output filejava.io.IOException
public byte[] getNextWord()
public void appendNextWord(byte[] word)
word
- an array of 4 bytes storing a memory word (on 32 bits)public int getNextInteger()
public int getNextBit()
public int readBitInByte(byte b, int i)
public byte setBitInByte(byte b, int i)
public void appendNextInteger(int v)
v
- an integer integer (4 bytes) to append to the encodingpublic float getNextFloat()
public void appendNextFloat(float x)
x
- a float value (4 bytes) to append to the encodingpublic static int fromByteArray(byte[] bytes)
bytes
- an array of four bytes encoding a 32 bits integerpublic static byte[] toByteArray(int value)
value
- an integer value to encodepublic int getByteCounter()