Code/C C++
[C++] 16진수 문자열을 2진수 문자열로 변환
Hide Code
2009. 4. 19. 12:41
CString strhex = _T("8CEF");
_tprintf(_T("hex: %s \n"), (LPCTSTR)strhex);
unsigned long dec = _tcstoul(strhex, NULL, 16);
_tprintf(_T("dec: %d \n"), dec);
CString bin;
CString buf;
TCHAR mod[2];
do
{
_ultot(dec % 2, mod, 2);
buf = mod;
buf += bin;
bin = buf;
} while (dec = dec / 2);
_tprintf(_T("bin: %s \n"), (LPCTSTR)bin);
_tprintf(_T("hex: %s \n"), (LPCTSTR)strhex);
unsigned long dec = _tcstoul(strhex, NULL, 16);
_tprintf(_T("dec: %d \n"), dec);
CString bin;
CString buf;
TCHAR mod[2];
do
{
_ultot(dec % 2, mod, 2);
buf = mod;
buf += bin;
bin = buf;
} while (dec = dec / 2);
_tprintf(_T("bin: %s \n"), (LPCTSTR)bin);
CString strhex = _T("8CEF");
_tprintf(_T("hex: %s \n"), (LPCTSTR)strhex);
unsigned long dec = _tcstoul(strhex, NULL, 16);
_tprintf(_T("dec: %d \n"), dec);
TCHAR bin[1024];
_ultot(dec, bin, 2);
_tprintf(_T("bin: %s \n"), bin);
_tprintf(_T("hex: %s \n"), (LPCTSTR)strhex);
unsigned long dec = _tcstoul(strhex, NULL, 16);
_tprintf(_T("dec: %d \n"), dec);
TCHAR bin[1024];
_ultot(dec, bin, 2);
_tprintf(_T("bin: %s \n"), bin);