Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number of bits in a byte (char) 1

Status
Not open for further replies.

peterworth

Programmer
Aug 18, 2004
80
0
0
GB
does the code

BYTE m_byte:5 ;

set the number of bits in m_byte to 5? if so, would this line:

BYTE ret:nCodeSize = *lpBufComp;

read nCodeSize number of bits from the buffer lpBufComp? the last question is this: after having done this, how would i move the pointer lpBufComp along to the next unread bit?
 
You still need to deal with padding issues. Most likely it will still have 8. Look into defining your own type within a struct using pramas

#pragma pack(push:1)

struct my_struct
{
unsigned fiveBits:5;
};

#pragma pack(pop)

I am not sure if this will work for you because (i think) it will still be represented with 8 bits. sizeof will most likely still return 1.

However, making an array of these and using pointer arithmetic MAY increment by 5 bits... not sure.

Matt
 
Is it C++ ???
Code:
BYTE m_byte:5 ; // outside of a structure declaration???
and especially:
BYTE ret:nCodeSize = *lpBufComp; // colon ???
May be this forum is dedicated to some other language now?...
 
> BYTE m_byte:5 ;
> set the number of bits in m_byte to 5?
No - it sets the range of the data, but doesn't really say much about how much storage it takes.
For example, if BYTE is an unsigned type, then from
Code:
m_byte = 31;
m_byte++;  // wraps around to zero

Oh, and unless you're using some non-standard compiler, this notation is only allowed within structures.

> BYTE ret:nCodeSize = *lpBufComp;
> read nCodeSize number of bits from the buffer lpBufComp?
No it won't.
You have to write a function to extract the next 'n' bits from a buffer, using bitwise operators.

Something like this prototype say.
Code:
// starting at bit bitnum of buff[bytenum], extract numbits
// updates bytenum and bitnum to index the next unused bit
int readbits ( unsigned char *buff, int *bytenum, int *bitnum, int numbits );

> However, making an array of these and using pointer arithmetic MAY increment by 5 bits
It won't. Pointer arithmetic only works down to the level of a byte.

--
 
ok, thanks everyone. i didnt know what the colon notation meant basically, and didnt know it can only be used within a struct.
 
yep, it looks like i'm going to have to read this in bit by bit because the data is stored sometimes in 8 bit chunks and sometimes in 9,10,11 or 12 bits. has anyone got any links with tutorials on bitwise stuff?
 
more specifically, how could i make an 11(for example) bit struct? i assume i'll have to use structs.

i then want to use this type as a key to a CMap instance, is this possible?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top