Skip to content

Instantly share code, notes, and snippets.

@YieldNull
Created November 21, 2015 07:02
Show Gist options
  • Save YieldNull/2f0f11e6b8c7d86a7870 to your computer and use it in GitHub Desktop.
Save YieldNull/2f0f11e6b8c7d86a7870 to your computer and use it in GitHub Desktop.
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