-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitOk.cpp
87 lines (67 loc) · 1.64 KB
/
BitOk.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* =====================================================================================
*
* Filename: bit.cpp
*
* Description:
*
* Version: 1.0
* Created: 2016年03月16日 15时06分33秒
* Last Modified: 2016年03月16日 15时06分33秒
* Revision: none
* Compiler: gcc
*
* Author: zt (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <vector>
unsigned char test[] =
{
0xaa, 0xaa, 0xaa, 0xaa, 0x6a,
0xaa, 0xaa, 0xaa, 0xaa, 0x7a,
0xaa, 0xaa, 0xaa, 0xaa, 0x8a,
0xaa, 0xaa, 0xaa, 0xaa, 0x9a,
};
unsigned char test2[128] = { 0 };
int BitSet ( unsigned char* data, int pos, unsigned char bitval )
{
if ( bitval )
data[pos / 8] |= ( 1 << ( pos % 8 ) );
else
data[pos / 8] &= ~ ( 1 << ( pos % 8 ) );
return 0;
}
int BitBit ( unsigned char* input, unsigned char* output, int linecnt, int lineBit, int validLineBit )
{
for ( int i = 0; i < linecnt; ++i )
{
for ( int j = 0; j < validLineBit; ++j )
BitSet ( output, validLineBit * i + j, input[ i * ( lineBit / 8 ) + j / 8 ] & ( 1 << ( j % 8 ) ) );
}
return 0;
}
int main ( int argc, char* argv[] )
{
for ( int i = 0; i < 20; ++i )
{
if ( ! ( i % 0x5 ) && i )
printf ( "\n" );
printf ( "%02x ", test[i] );
}
printf ( "\n" );
printf ( "\n" );
//BitSet ( test, 17, 0 );
BitBit ( test, test2, 4, 40, 36 );
for ( int i = 0; i < 20; ++i )
{
if ( ! ( i % 0x5 ) && i )
printf ( "\n" );
printf ( "%02x ", test2[i] );
}
printf ( "\n" );
return 0;
}