본문 바로가기

My Study/Programming&Theory

IEEE Std 754

 컴퓨터 구조 시간에 교수님이 레포트로 내주신 내용입니다.

Your work is to write your own program in C language, which converts a decimal floating-point or real number to an internal single-precision representation in IEEE Std 754 format and vice versa. Refer to Chapter 3 of your textbook for IEEE Std 754 representation and conversion procedure.
In order to get a high grade, you should run as many different inputs as possible for both directions of conversion. The followings are examples of test inputs and outputs. (Note here that the two prefixes ‘d’ and ‘i’ represent decimal and internal representations, respectively, and ‘xEy’ denotes ‘x × 10y’ in decimal notation.)
 
d -0.75 => i 1011 1111 0100 0000 0000 0000 0000 0000
Input => Output
i 1100 0000 1010 0000 0000 0000 0000 0000 => d -5.0
d 3.14 => i 0??? ???? ???? ???? ???? ???? ???? ????
d -2.7E-5 => i 1??? ???? ???? ???? ???? ???? ???? ????
i ???? ???? ???? ???? ???? ???? ???? ???? => d ?.?????E???
……

단순히 10진 소수를 입력하면 2진수로 표현하고
2진수를 입력 받으면 10진수로 표현하도록 바꿔주는 프로그램
입니다.

 그냥 입력해도 되고 정규화된 식으로 입력해도 됩니다.

IEEE 표현 방식에 대해선 인터넷에 자세하게 나와있습니다. 간단히 그림으로만 표현하겠습니다.


단정도 같은 경우는 32bit이며 배정도 같은 경우는 64bit로 표현이 됩니다.
그리고 Exponent는 전부 0과 전부 1은 예약된 부분이라 사용할 수 없습니다.

Bias는
단정도일 경우 : 127
배정도일 경우 : 1023

입니다.
 
해당 코드를 짜는 방법은 여러가지가 있지만 위 공식을 그대로 사용해 코드로 짰습니다.
아직 레포트 제출 기간이 남아있어 코드는 레포트 제출 기간이 끝난 후 올리겠습니다. ( 기한 끝.. 올렸습니다. )

제가 만든 프로그램으로 실행해본 결과입니다. 
 

소스코드 입니다.

'My Study > Programming&Theory' 카테고리의 다른 글

Get clipboard data  (0) 2011.05.17
프로세스 생성 막기  (2) 2011.04.28
DFS, BFS, UCS  (1) 2011.04.10
Python Eclipse에서 코딩하기  (1) 2011.02.25
병렬 프로그래밍  (1) 2011.02.10