如何将char类型转换为16二进制字符串 [英] how to convert char type to 16 binary string

查看:298
本文介绍了如何将char类型转换为16二进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将char类型转换为16个二进制字符串?

例如如下:



如果变量temp是char类型,并且它的ini值是255,

i wanne得到FF。



所以如何转换?

谢谢for relpy。

how to convert char type to 16 binary string?
for example as below:

if variable temp is char type,and it's ini value is 255,
i wanne get "FF".

so how to convert ?
thanks for relpy.

推荐答案

您可以使用 sprintf [ ^ ](或 printf ,取决于您对此类目的的需求),例如

You may use sprintf[^] (or printf, depending on your needs for such a purpose), e.g.
#include <stdio.h>

int main()
{
  unsigned char u = 255;

  printf("%02X\n", u);

  return 0;
}





您也可以自己编写一个临时函数。



You might as well code an ad hoc function yourself.


这篇关于如何将char类型转换为16二进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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