如何以十六进制打印字节? [英] How do I print bytes as hexadecimal?

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

问题描述

我知道在C#中你可以使用String.Format方法。但是你怎么在C ++中做到这一点呢?是否有一个函数,允许我将一个字节转换为十六进制?

I know in C# you can use String.Format method. But how do you do this in C++? Is there a function that allows me to convert a byte to a Hex?? Just need to convert a 8 byte long data to Hex, how do I do that?

推荐答案

你可以转换一个字节unsigned char)在一个数组中,如下所示

Well you can convert one byte (unsigned char) at a time into a array like so

char buffer [17];
buffer[16] = 0;
for(j = 0; j < 8; j++)
    sprintf(&buffer[2*j], "%02X", data[j]);

这篇关于如何以十六进制打印字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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