2014-03-05 03:15:03 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/stream.h>
|
2014-03-09 02:38:47 +04:00
|
|
|
#include <winpr/bitstream.h>
|
2014-03-05 03:15:03 +04:00
|
|
|
|
|
|
|
void BitStrGen()
|
|
|
|
{
|
2014-03-05 21:03:10 +04:00
|
|
|
DWORD i, j;
|
2014-03-05 03:15:03 +04:00
|
|
|
char str[64];
|
|
|
|
|
2014-08-19 20:24:58 +04:00
|
|
|
for (i = 0; i < 256;)
|
2014-03-05 03:15:03 +04:00
|
|
|
{
|
2014-03-05 21:03:10 +04:00
|
|
|
printf("\t");
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
/* Least Significant Bit First */
|
|
|
|
str[0] = (i & (1 << 7)) ? '1' : '0';
|
|
|
|
str[1] = (i & (1 << 6)) ? '1' : '0';
|
|
|
|
str[2] = (i & (1 << 5)) ? '1' : '0';
|
|
|
|
str[3] = (i & (1 << 4)) ? '1' : '0';
|
|
|
|
str[4] = (i & (1 << 3)) ? '1' : '0';
|
|
|
|
str[5] = (i & (1 << 2)) ? '1' : '0';
|
|
|
|
str[6] = (i & (1 << 1)) ? '1' : '0';
|
|
|
|
str[7] = (i & (1 << 0)) ? '1' : '0';
|
|
|
|
str[8] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Most Significant Bit First */
|
|
|
|
str[7] = (i & (1 << 7)) ? '1' : '0';
|
|
|
|
str[6] = (i & (1 << 6)) ? '1' : '0';
|
|
|
|
str[5] = (i & (1 << 5)) ? '1' : '0';
|
|
|
|
str[4] = (i & (1 << 4)) ? '1' : '0';
|
|
|
|
str[3] = (i & (1 << 3)) ? '1' : '0';
|
|
|
|
str[2] = (i & (1 << 2)) ? '1' : '0';
|
|
|
|
str[1] = (i & (1 << 1)) ? '1' : '0';
|
|
|
|
str[0] = (i & (1 << 0)) ? '1' : '0';
|
|
|
|
str[8] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\"%s\",%s", str, j == 3 ? "" : " ");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2014-03-05 03:15:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestBitStream(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
wBitStream* bs;
|
|
|
|
BYTE buffer[1024];
|
|
|
|
ZeroMemory(buffer, sizeof(buffer));
|
|
|
|
bs = BitStream_New();
|
2015-05-29 14:46:50 +03:00
|
|
|
if (!bs)
|
|
|
|
return 1;
|
2014-03-05 03:15:03 +04:00
|
|
|
BitStream_Attach(bs, buffer, sizeof(buffer));
|
2014-03-05 21:03:10 +04:00
|
|
|
BitStream_Write_Bits(bs, 0xAF, 8); /* 11110101 */
|
|
|
|
BitStream_Write_Bits(bs, 0xF, 4); /* 1111 */
|
|
|
|
BitStream_Write_Bits(bs, 0xA, 4); /* 0101 */
|
2014-03-05 21:56:26 +04:00
|
|
|
BitStream_Flush(bs);
|
2014-08-19 20:24:58 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
|
2014-03-05 21:03:10 +04:00
|
|
|
BitStream_Write_Bits(bs, 3, 2); /* 11 */
|
|
|
|
BitStream_Write_Bits(bs, 0, 3); /* 000 */
|
|
|
|
BitStream_Write_Bits(bs, 0x2D, 6); /* 101101 */
|
|
|
|
BitStream_Write_Bits(bs, 0x19, 5); /* 11001 */
|
2014-03-05 21:56:26 +04:00
|
|
|
//BitStream_Flush(bs); /* flush should be done automatically here (32 bits written) */
|
2014-08-19 20:24:58 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
|
2014-03-05 21:56:26 +04:00
|
|
|
BitStream_Write_Bits(bs, 3, 2); /* 11 */
|
|
|
|
BitStream_Flush(bs);
|
2014-08-19 20:24:58 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
|
2014-03-05 21:56:26 +04:00
|
|
|
BitStream_Write_Bits(bs, 00, 2); /* 00 */
|
|
|
|
BitStream_Write_Bits(bs, 0xF, 4); /* 1111 */
|
|
|
|
BitStream_Write_Bits(bs, 0, 20);
|
|
|
|
BitStream_Write_Bits(bs, 0xAFF, 12); /* 111111110101 */
|
|
|
|
BitStream_Flush(bs);
|
2014-08-19 20:24:58 +04:00
|
|
|
BitDump(__FUNCTION__, WLOG_INFO, buffer, bs->position, BITDUMP_MSB_FIRST);
|
2014-03-05 03:15:03 +04:00
|
|
|
BitStream_Free(bs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|