Skip to content

Instantly share code, notes, and snippets.

@ironpark
Created May 20, 2015 12:26
Show Gist options
  • Save ironpark/d1c11bf8ef83cfde20a8 to your computer and use it in GitHub Desktop.
Save ironpark/d1c11bf8ef83cfde20a8 to your computer and use it in GitHub Desktop.
typedef struct {
int bit1 : 1;
int bit2 : 1;
int bit3 : 1;
int bit4 : 1;
int bit5 : 1;
int bit6 : 1;
int bit7 : 1;
int bit8 : 1;
} Bit;
union bit8
{
unsigned char uchar;
Bit bits;
};
int main(){
int index = 0;
byte code[9000];
memset(code, 0, 9000);
int size = 9000;
byte* compressbyte = new byte[size / 8];
for (size_t i = 0,j=0; i < size; i+=8,j++)
{
bit8 byte1;
byte1.bits = Bit{ code[i], code[i + 1], code[i + 2], code[i + 3], code[i + 4], code[i + 5], code[i + 6], code[i + 7] };
compressbyte[j] = byte1.uchar;
}
for (size_t i = 0; i < 9000/8; i++)
{
printf("%d\n", compressbyte[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment