十进制到十六进制

编程入门 行业动态 更新时间:2024-10-26 06:28:54
本文介绍了十进制到十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 有人能告诉我如何将十进制数转换成后续格式的十六进制数。 如果我给出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>在消息中写道 news:11 ********************** @ f14g2000cwb.googlegr oups ... "sara" <sa************@rediffmail> wrote in message news:11**********************@f14g2000cwb.googlegr oups... 我能够得到十六进制值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>在消息中写道新闻:11 ********************** @ f14g2000cwb.googlegr oups ... "sara" <sa************@rediffmail> wrote in message news:11**********************@f14g2000cwb.googlegr oups... 我能够得到十六进制值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>写在 新闻:11 ********************** @ z14g2000cwz.googlegr oups: "sara" <sa************@rediffmail> wrote in news:11**********************@z14g2000cwz.googlegr oups: 蒲公英写道: dandelion wrote: " sara" < SA ************ @ rediffmail>在消息中写道新闻:11 ********************** @ f14g2000cwb.googlegr oups ... "sara" <sa************@rediffmail> wrote in message news:11**********************@f14g2000cwb.googlegr oups... >我能够得到十六进制值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 -> --

更多推荐

十进制到十六进制

本文发布于:2023-10-09 10:32:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:十进制到十六进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!