Line | |
---|
1 | /**
|
---|
2 | * @file bitwise.c
|
---|
3 | * @author myusgun <myusgun@gmail.com>
|
---|
4 | */
|
---|
5 | #include "cf_bitwise.h"
|
---|
6 |
|
---|
7 | #include <stdio.h>
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | #ifdef _WIN32
|
---|
11 | # include <winsock2.h>
|
---|
12 | # pragma comment(lib, "ws2_32.lib")
|
---|
13 | #else
|
---|
14 | # include <arpa/inet.h>
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | int main (void)
|
---|
18 | {
|
---|
19 | cf_byte in[sizeof (int)] = {0x00,};
|
---|
20 | cf_byte out[sizeof (int)] = {0x00,};
|
---|
21 | unsigned int integer = 0x6b8b4567; // random byte
|
---|
22 | unsigned int * bi = (unsigned int *)in; // type punning
|
---|
23 | unsigned int * bo = (unsigned int *)out; // type punning
|
---|
24 |
|
---|
25 | // print original
|
---|
26 | printf ("data : 0x%08x\n", integer);
|
---|
27 | printf ("---------------------------\n");
|
---|
28 |
|
---|
29 | // if in little-endian environment,
|
---|
30 | // convert integer to big-endian for pure bit-array
|
---|
31 | *bi = htonl (integer);
|
---|
32 | CF_Bitwise_ShiftLeft (in, sizeof (int) * 8, 4, out);
|
---|
33 |
|
---|
34 | // print result of operation
|
---|
35 | printf ("integer << 4 : 0x%08x\n", integer << 4);
|
---|
36 | printf ("byteArray << 4 : 0x%08x\n", ntohl (*bo));
|
---|
37 |
|
---|
38 | return 0;
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.