digit.cpp

来自「CEL代码的中间编译」· C++ 代码 · 共 64 行

CPP
64
字号
// DIGIT.cpp: implementation of the DIGIT class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CREATOR.h"
#include "DIGIT.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

DIGIT::DIGIT()
{

}

DIGIT::~DIGIT()
{

}

int DIGIT::XtoD(char ch)
{char ch2=toupper(ch);
 if(ch2>='0'&&ch2<='9') return ch2-'0';
 if(ch2>='A'&&ch2<='F') return ch2-'A'+10;
 return 0;
}

int DIGIT::XtoD(CString string)
{int i=0,s=0;
 BOOL flag=FALSE;  
	while(1)
	{char ch=string.GetAt(i);
		if(!IsXDigitchar(string.GetAt(i))){i++;continue;}
     //如果是数字串结尾了,就跳出循环
	 s*=16;
     s+=XtoD(string.GetAt(i++));
	 if(i==string.GetLength()||!IsXDigitchar(string.GetAt(i))) break;
     }
 return s;
}

BOOL DIGIT::IsXDigitchar(char ch)
{char ch2=toupper(ch);
 if((ch2>='0'&&ch2<='9')||(ch2>='A'&&ch2<='F'))
 return TRUE;
 else return FALSE;
}

BOOL DIGIT::IsDDigitchar(char ch)
{if(ch>='0'&&ch<='9') return TRUE;
 else return FALSE;

}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?