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

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

问题描述

我知道在 C# 中你可以使用 String.Format 方法.但是你如何在 C++ 中做到这一点?是否有允许我将字节转换为十六进制的函数?只需要将 8 字节长的数据转换为十六进制,我该怎么做?

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?

推荐答案

好吧,您可以一次将一个字节(无符号字符)转换为这样的数组

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天全站免登陆