Skip to content

Commit 283b251

Browse files
committed
(incomplete) byte order demo test code (endianness)
1 parent 39ac941 commit 283b251

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

byte_order.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
// 65535
5+
// 32767
6+
7+
char *generate_buffer(int num) {
8+
char *buffer = malloc(num * 7 + 1);
9+
int i;
10+
11+
for(i = 0; i < num; i++) {
12+
buffer[(i*7)] = 40000;
13+
buffer[(i*7 + 2)] = 1;
14+
buffer[(i*7 + 6)] = 'a';
15+
}
16+
buffer[(num * 7)] = '\0';
17+
return buffer;
18+
}
19+
20+
int main(int argc, char* argv[]) {
21+
char *buf = generate_buffer(1);
22+
int i;
23+
for (i = 0; i < 8; i++)
24+
{
25+
if (i > 0) printf(":");
26+
printf("%02X", buf[i]);
27+
}
28+
printf("\n");
29+
return 0;
30+
}

0 commit comments

Comments
 (0)