- 论坛徽章:
- 0
|
小玩意,打印内存指定长区域的二进制
void printfBits(FILE *fpA,unsigned char * pstChar, int uiCharLength)
{
unsigned int j = 1;
unsigned int uiBytes;
for (uiBytes = 0; uiBytes < uiCharLength; uiBytes++)
{
unsigned char ucTemp;
ucTemp = *((unsigned char *)pstChar + uiBytes);
unsigned char BIT=1;
unsigned char flag=1;
unsigned int i;
for(i = 7; i>=0; i--)
{
flag=(BIT<<i);
if( (flag&ucTemp) == flag )
{
fprintf(fpA, "%d", 1);
}
else
{
fprintf(fpA, "%d", 0);
}
if ( ((j++)% == 0)
{
fprintf(fpA, "%s", " " ;
}
if( i == 0)
{
break;
}
}
if ( uiBytes == uiCharLength-1 )
{
break;
}
}
} |
|