Floating Point 방식의 변수를 Bit 그대로 출력하는 방법


1. Union 활용

Union은 같은 메모리 주소에 여러가지 형태로 값을 저장하는 변수이다.

union{

float a;

int b;

};

a(float)에 값 저장 후 b(int) 출력


또는 typedef를 활용하여 아래와 같이 구성하면 된다.

typedef union{

float float_t;

int int_t;

}int_float_t;


int_float_t a;

a.float_t = 3.14;

printf("%x\n", a.int_t);


2. Pointer 활용

float a = 1.2345; //float value

int* b = (int*)&a;

*b를 출력

'Programming > C Language' 카테고리의 다른 글

static  (0) 2018.07.13
가변 인자(variable arguments) stdarg.h  (0) 2017.12.11
extern  (0) 2017.06.21
static  (0) 2017.06.20
전처리기 명령어  (0) 2017.06.07

+ Recent posts