Commit ba7d3671 authored by Jiachen,Chen's avatar Jiachen,Chen

Modified TestLittleEndian

parent cd5b2368
......@@ -6,30 +6,30 @@
*/
#include "TestLittleEndian.hh"
#include <arpa/inet.h>
#include <endian.h>
#include <inttypes.h>
TestLittleEndian::TestLittleEndian() = default;
TestLittleEndian::~TestLittleEndian() = default;
int TestLittleEndian::initialize(ErrorHandler* errh __attribute ((__unused__))) {
unsigned i;
union {
uint32_t i;
uint8_t a[sizeof (uint32_t)];
} u;
u.i = 0x12345678;
for (i = 0; i < sizeof (uint32_t); i++)
printf("%02" PRIx8, u.a[i]);
static void print_buf(void *content, size_t size) {
size_t i;
uint8_t *ptr = (uint8_t *)content;
for (i = 0; i < size; i++) {
printf("%02" PRIx8, ptr[i]);
}
printf("\n");
}
u.i = htonl(0x12345678);
for (i = 0; i < sizeof (uint32_t); i++)
printf("%02" PRIx8, u.a[i]);
printf("\n");
int TestLittleEndian::initialize(ErrorHandler* errh __attribute ((__unused__))) {
uint32_t i;
i = 0x12345678;
print_buf(&i, sizeof(i));
i = htobe32(0x12345678);
print_buf(&i, sizeof(i));
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment