基本信息
源码名称:c++ 浮点数二进制格式
源码大小:0.03M
文件格式:.zip
开发语言:C/C++
更新时间:2019-04-09
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
输入一个十进制浮点数返回它的二进制表现


// FltDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Flt.h"
#include "FltDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

union FDATA    // Declare union type
{
	BYTE	ch[4];
	float	f;
} ;
     
/////////////////////////////////////////////////////////////////////////////
// CFltDlg dialog

CFltDlg::CFltDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFltDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFltDlg)
	m_1 = 0.0f;
	m_2 = _T("");
	m_3 = _T("");
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFltDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFltDlg)
	DDX_Text(pDX, IDC_EDIT1, m_1);
	DDX_Text(pDX, IDC_EDIT2, m_2);
	DDX_Text(pDX, IDC_EDIT3, m_3);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFltDlg, CDialog)
	//{{AFX_MSG_MAP(CFltDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFltDlg message handlers

BOOL CFltDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFltDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon   1) / 2;
		int y = (rect.Height() - cyIcon   1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CFltDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CFltDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
/*
浮点数格式如下:	
		 s  eeeeeeee  wwwwwww wwwwwwww wwwwwwww
s		=符号位,0正1负
e		=指数位,运算值:eeeeeeee-01111111
w		=尾数位,默认尾数前1个bit=1,即应读做24bit: 1wwwwwww wwwwwwww wwwwwwww
EXAMPLE -6.8 = C0D9999A ;内存中存放:9A 99 D9 C0
基本函数
01(3) 标号: FMUL 功能:浮点数乘法
02(4) 标号: FDIV 功能:浮点数除法
03(5) 标号: FMOV 功能:浮点数传送
04(6) 标号: FCMP 功能:浮点数代数值比较(不影响待比较操作数)
05(7) 标号: FADD 功能:浮点数加法
06(8) 标号: FSUB 功能:浮点数减法
07(9) 标号: DTOF 功能:三字节十六进制定点数转换成格式化浮点数
08(10)标号: FINT 功能:浮点取整函数
09(11)标号: FSGN 功能:浮点符号函数
10(12)标号: FCLR 功能:浮点数清零
11(13)标号: FZER 功能:浮点数判零

*/
	FDATA  v; 
	int i,ib,yb;
	BYTE byt[8]={1,2,4,8,16,32,64,128};
	BYTE bwk;
	CString str;
	v.f=m_1;
	for(i=31;i>=0;i--){
		if((i==30)||(i==22))str =" ";
		ib=i/8;
		yb=i%8;
		if((v.ch[ib]&byt[yb])==byt[yb])str ="1"; else str ="0";		
	}
	m_2=str;
	str.Empty();
	for(i=3;i>=0;i--){
		bwk=v.ch[i]&0x0f0;bwk>>=4;bwk ='0';
		if(bwk>'9')bwk =7;
		str =bwk;
		bwk=v.ch[i]&0x0f;bwk ='0';
		if(bwk>'9')bwk =7;
		str =bwk;
	}
	m_3=str;
	UpdateData(FALSE);
}

void CFltDlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
}