如何将int值转换为十六进制? [英] How do I convert int value to hex?

查看:398
本文介绍了如何将int值转换为十六进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我是C和C ++的新手,



我使用UNICODE编写VC ++中的MFC。



这对你来说很简单但对我来说并不容易,问题很难解决如下:



int x = 19;



char y [2];



我想将值x移动到y,如'0013'// 00 13 =十六进制是十进制19



所以我试图



CString str = _T();



str.Format(_T(%d),x);



WideCharToMultiByte(CP_ACP ,0,s.GetBuffer(),str.GetLength(),y,sizeof(y),NULL,NULL);



完成后,但是我调试y,y有'0x49'和'0x57'(0x49 ='1',0x57 ='9')



我想获得2字节字符:y [0] = 0x00,y [1] = 0x13



在使用unicode的C ++世界中,转换对我来说非常困难



请帮帮我。



我的尝试:



更多的一天浪费了这个问题。

As I am a novice of C and C++,

I am coding of MFC in VC++ using UNICODE.

It is simple for you but not easy for me, the problem is difficult as follows:

int x = 19;

char y[2];

I want to move the value x to y like as '0013' // 00 13 = hex is decimal 19

So I tried to

CString str = _T("");

str.Format(_T("%d"), x);

WideCharToMultiByte(CP_ACP, 0, s.GetBuffer(), str.GetLength(), y, sizeof(y), NULL, NULL);

After doing it, but as I debugging y, y has '0x49' and '0x57' (0x49='1', 0x57='9')

I want to get the 2 byte char y : y[0] = 0x00, y[1] = 0x13

In the world of C++ with unicode, Conversion is very difficult for me

Please help me.

What I have tried:

More one day wasted for this problem.

推荐答案

使用 %X CString :: Format 调用中的类型说明符。如果你在UNICODE工作,不要打扰 WideCharToMultiByte 的东西,只需保留UNICODE中的所有东西。



Use the %X type specifier in your CString::Format call. Do not bother with the WideCharToMultiByte stuff if you are working in UNICODE, just keep every thing in UNICODE.

CString str;
str.Format(L"%X", x);





在MSDN中查找 CString :: Format


这篇关于如何将int值转换为十六进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆