Feb 3, 2011 at 8:27pm UTC
I want to be able to read and write nibbles. Also how could I make sure that all my nibbles go into a file an even number of times so that there is no crash(or anything like that)?
How would I go about this?
Thanks
Last edited on Feb 3, 2011 at 8:31pm UTC
Feb 3, 2011 at 8:30pm UTC
I've often wondered this my self, it think it would require some serious low level control of the bit. if it's even possible
Feb 3, 2011 at 9:22pm UTC
You can simply use bit shifting to set whichever bits you like, e.g. with the following functions:
1 2 3 4 5 6 7 8 9 10
template <class I> void setNibble(I& o,int index,I nibbleVal)
{
o&=~(15<<(index*4)); //blank nibble
o|=nibbleVal<<(index*4); //set new value
}
template <class I> I getNibble(const I& o,int index)
{
return (o&(15<<(index*4)))>>(index*4);
}
Integrate them into a class and you're done.
Last edited on Feb 3, 2011 at 9:24pm UTC
Feb 3, 2011 at 10:14pm UTC
Er, your file must always be a multiple of two nibbles long... so you will have to consider that when you access the file.