summaryrefslogtreecommitdiff
path: root/CSAPP/chap2/encoding.c
blob: 7a3b0c91dde0fcee3c91478ac9a6c22125d828e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>

int main(void)
{
	int		a = 2809;
	float		b = 2809;
	unsigned char	*p;
	int i = 0;

	/* print int and float values as an hexadecimal unsigned integer */
	p = (unsigned char *)&a;
		printf(" Int: 0x");
	for (i = 0; i < sizeof(int); i++) {
		printf("%.2x", p[i]);
		printf("\n");
	}

	p = (unsigned char *)&b;
	printf(" Float: 0x");
	for (i = 0; i < sizeof(int); i++) {
		printf("%.2x", p[i]);
		printf("\n");
	}
	return 0;
}