十进制到十六进制 [英] decimal to hexadecimal

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

问题描述

大家好,

有人能告诉我如何将十进制数转换成后续格式的
十六进制数。


如果我给出numia = 100的deciaml值,我需要以hexa

十进制形式输出为0x64。


我能够得到十六进制值64个char类型。但实际上我需要输出格式为0x64的输出。

有人能告诉我如何处理这种转换吗?


谢谢


sara

Hi everybody,
can anyone tell me how to convert decimal number into
hexadecimal of the folloxing format.

If I give deciaml value of num=100, I need the output in the hexa
decimal form as 0x64.

I can able to get teh hex value 64 which of type char. But actually I
want the ouput in the format of 0x64.
can anyone tell me how to handle this conversion?

Thanks

sara

推荐答案



" sara" ; < SA ************ @ rediffmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

"sara" <sa************@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我能够得到十六进制值64,类型为char。但实际上我想要输出格式为0x64。
谁能告诉我如何处理这种转换?
I can able to get teh hex value 64 which of type char. But actually I
want the ouput in the format of 0x64.
can anyone tell me how to handle this conversion?




sprintf(your_string, 0x%x,your_value);



sprintf(your_string, "0x%x", your_value);




蒲公英写道:

dandelion wrote:
" sara" < SA ************ @ rediffmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
"sara" <sa************@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我能够得到十六进制值64的char类型。但实际上
我希望输出格式为0x64。
谁能告诉我如何处理这种转换?
I can able to get teh hex value 64 which of type char. But actually I want the ouput in the format of 0x64.
can anyone tell me how to handle this conversion?



sprintf(your_string," 0x% x",your_value);



sprintf(your_string, "0x%x", your_value);




嗨蒲公英,

Printf stmt可以按照你所说的格式打印。

但是我希望它存储在一个可变的。

我只是通过类型转换来做它。


a = 100; / *需要将其转换为hexa * /


long b = 0x0 | a;

对我来说还可以。现在。


如何感谢蒲公英。


Sara



Hi dandelion,
Printf stmt can print in the desired format as what you said.
But I want it to store in a vaiable.
I did it simply by type casting.

a =100; /* need to convert it to hexa*/

long b=0x0 | a;
its ok for me . now .

Any how thanks dandelion.

Sara


"萨拉" < SA ************ @ rediffmail.com>写在

新闻:11 ********************** @ z14g2000cwz.googlegr oups.com:
"sara" <sa************@rediffmail.com> wrote in
news:11**********************@z14g2000cwz.googlegr oups.com:

蒲公英写道:

dandelion wrote:
" sara" < SA ************ @ rediffmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
"sara" <sa************@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
>我能够得到十六进制值64的char类型。但实际上我>想要输出格式为0x64。
>谁能告诉我如何处理这种转换?
sprintf(your_string," 0x%x",your_value);
> I can able to get teh hex value 64 which of type char. But actually I > want the ouput in the format of 0x64.
> can anyone tell me how to handle this conversion?
sprintf(your_string, "0x%x", your_value);



嗨蒲公英,
Printf stmt can按照你所说的格式打印。
但我想把它存放在一个可变的版本中。
我只是通过类型转换来实现它。



Hi dandelion,
Printf stmt can print in the desired format as what you said.
But I want it to store in a vaiable.
I did it simply by type casting.




你觉得很困惑。

a = 100; / *需要将其转换为hexa * /


这将''a'设置为100十进制,0x64,0144(八进制)和1100100(二进制)所有

同时。值是值是值。你如何展示它

取决于你。

长b = 0x0 |一个;


这实际上什么都不做。编译器可能会优化它或者

生成这样的程序集:


##将''a''输入到寄存器''r3''
li r3,a @ l

lwz r3,@ ha(r3)


## Bit-OR zero(r0)with ''a'',无用的操作。

或r3,r0,r3


##将结果存储到''b''。

li r4,b @ l

stw r3,b @ ha(r4)

对我来说还可以。现在f



You are confused, I think.
a =100; /* need to convert it to hexa*/
This sets ''a'' to 100 decimal, 0x64, 0144 (octal), and 1100100 (binary) all
at the same time. The value is the value is the value. How you display it
is up to you.
long b=0x0 | a;
This effectively does nothing. The compiler might optimize this away or
produce assembly like this:

## Get ''a'' into register ''r3''
li r3,a@l
lwz r3,a@ha(r3)

## Bit-OR zero (r0) with ''a'', useless operation.
or r3,r0,r3

## Store result into ''b''.
li r4,b@l
stw r3,b@ha(r4)
its ok for me . now . f




这不是你想的那样。


-

- 标记 - >

-



It''s not what you think then.

--
- Mark ->
--


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

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