将int格式化为十六进制字符串 [英] Format int to hex string

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

问题描述

我有一些要转换为字符串但为十六进制的int值.此十六进制值应始终以2位数字格式设置.

I have some int values that I want to convert to a string but in hex. This hex value should be formatted always by 2 digits.

以下示例:

int a = 10;
int b = 20;

//returns the value in hex
string c = a.toString("x"); // a
string d = b.toString("x"); // 14

我想要的是始终使十六进制值产生两位数.不仅显示为"a",还显示为"0a".

What I want is that always that the hex value results in two digits. Shows like "0a", not only "a".

我正在使用将int转换为格式化的字符串,

I'm using convert a int to a formatted string,

int e = 1;
string f = e.toString("D2"); // 01

有办法将这两件事结合在一起吗?要将int转换为十六进制格式的字符串?

Have a way to the two things together? To convert the int to a hex formatted string?

推荐答案

您可以使用此

int e = 1;
string f = e.toString("x2");  

这篇关于将int格式化为十六进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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