Skip to content

Instantly share code, notes, and snippets.

@YieldNull YieldNull/hexout.c
Created Nov 21, 2015

Embed
What would you like to do?
Display memory block via Hexadecimal.
#include <stdio.h>
/**
* Display memory block via Hexadecimal.
* From lower to higher address.
**/
void hexOut(unsigned char c) {
printf("%x", c & 0xF);
printf("%x", (c >> 4) & 0xF);
}
void displayInHex(void * block, int size) {
unsigned char *tmp = (unsigned char *) block;
int i;
for (i = 0; i < size; i++) {
hexOut(*(tmp + i));
if (i % 2 == 1)
printf(" ");
}
printf("\n");
}
struct demo {
int a;
long b;
double c;
};
int main() {
double a = 0.3;
struct demo d = { 1, 2, 0.3 };
// double 0.3 in hex is 0x3fd3333333333333
displayInHex(&a, sizeof(a)); //3333 3333 3333 3df3
displayInHex(&d, sizeof(d)); //1000 0000 0000 0000 2000 0000 0000 0000 3333 3333 3333 3df3
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.