M
matobinder
I need to write some code that deals with some memory images. In
essence, these images are just a collection of data, integers, bools,
floats, and so on.
The mucky part with this case is that nothing falls on byte boundries,
so I can't just use the ostream::write() stuff... Let me quick explain
this with an simple example.
I have an image data length of 2 bytes.
So Byte 0, and Byte 1.
Byte 0, Bit 0 ; is a bool
Byte 0, Bit 1 ; is a bool
Byte 0, Bits 2,3 ; represents a value 0,1,2, or 3
Byte 0, Bits 4,5,6,7
AND Byte 1, Bits 0,1,2,3 ; Represent a int(max 255)
Byte 1, Bits 4,5,6,7 ; Always 1111
So for example, I need to generate those two bytes, based on my normal
values in code.
Lets say I have:
int firstBit = 1; // always 0 or 1
int secondBit = 1; // always 0 or 1
int status = 0; //always 0 , 1, 2, or 3
int dataWord = 42; // number from 0-255 //bits 00101010
int tag = 15; // bits 1111
So I would need to generate(listing this in binary)
Byte 0 is: Byte 1 is:
1 1 00 0010 1010 1111
So basically I end up with a bit pattern of "1100001010101111"
I need to go both ways(Generating the bit patterns from the values,
and generating values from the bit pattern)
I'm trying to think of a good way to implement a library to assist
this. I understand all the things I need to worry about dealing with
byte ordering, and signed/unsigned.
I was thinking a good way to do this(maybe?) is just store the bits as
an array of char's. The 8 times the require memory for doing that
wouldn't be bad, as the largest image is 64k(and they willl NEVER be
bigger... its in hardware)
But first, are their any libraries or tools already in existance in
C/C++ that could greatly assist this. I know normal bit operators and
shifting, just looking for a more comprehensive set of tools for this.
I know C, and I am figuring out C++, I see C++ has a bitset class. Not
sure if this is overkill for what I want to do though.
I'm just starting on the begingings of this project and am just trying
to figure out some initial ideas of how I want to work on this. Any
pointers on this would be appreciated.
-mato
essence, these images are just a collection of data, integers, bools,
floats, and so on.
The mucky part with this case is that nothing falls on byte boundries,
so I can't just use the ostream::write() stuff... Let me quick explain
this with an simple example.
I have an image data length of 2 bytes.
So Byte 0, and Byte 1.
Byte 0, Bit 0 ; is a bool
Byte 0, Bit 1 ; is a bool
Byte 0, Bits 2,3 ; represents a value 0,1,2, or 3
Byte 0, Bits 4,5,6,7
AND Byte 1, Bits 0,1,2,3 ; Represent a int(max 255)
Byte 1, Bits 4,5,6,7 ; Always 1111
So for example, I need to generate those two bytes, based on my normal
values in code.
Lets say I have:
int firstBit = 1; // always 0 or 1
int secondBit = 1; // always 0 or 1
int status = 0; //always 0 , 1, 2, or 3
int dataWord = 42; // number from 0-255 //bits 00101010
int tag = 15; // bits 1111
So I would need to generate(listing this in binary)
Byte 0 is: Byte 1 is:
1 1 00 0010 1010 1111
So basically I end up with a bit pattern of "1100001010101111"
I need to go both ways(Generating the bit patterns from the values,
and generating values from the bit pattern)
I'm trying to think of a good way to implement a library to assist
this. I understand all the things I need to worry about dealing with
byte ordering, and signed/unsigned.
I was thinking a good way to do this(maybe?) is just store the bits as
an array of char's. The 8 times the require memory for doing that
wouldn't be bad, as the largest image is 64k(and they willl NEVER be
bigger... its in hardware)
But first, are their any libraries or tools already in existance in
C/C++ that could greatly assist this. I know normal bit operators and
shifting, just looking for a more comprehensive set of tools for this.
I know C, and I am figuring out C++, I see C++ has a bitset class. Not
sure if this is overkill for what I want to do though.
I'm just starting on the begingings of this project and am just trying
to figure out some initial ideas of how I want to work on this. Any
pointers on this would be appreciated.
-mato