如何在HEX中表示分数? [英] How to represent a fraction in HEX?

查看:78
本文介绍了如何在HEX中表示分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到这个问题的答案,我在想

解决方案必须非常明显,因此我当然无法看到
看不到它。


我希望在DEC中取一小部分说.4并将其转换为HEX值。

我还需要找到一种方法来确定是否一个数字是

HEX中的一小部分并将其转换回DEC。


(这将来自反汇编,我们正在学习这个/>
故障排除目的)


我的导师向我们展示了这一点,但他必须成为地球上最无聊的b $ b人老实说,我想我打了一秒钟。我确实想成为一名专业的计算机程序员,而这本书中没有列出任何关于此的内容。但是我们有一个家庭作业

我有3天时间完成这项工作。 HEX和DEC中有一个包含50个数字的列表,其中包括
。我不会在这里列出它们因为我想自己解决问题,我恰好需要指向正确的方向来解决它们,配方或其他东西会很好。


BTW我已经尝试了calc.exe HEX功能,当我选择.4然后

切换到HEX我得到0,我知道这不是正确的答案(虽然
解释了很多与windows有关的问题:)


我知道问题与拆卸有关,但课程是

C ++所以我真的希望不要因为无关紧要的帖子而受到抨击。


提前感谢您的回复。 ..顺便说一句,电子邮件已经完成,所以

只在这里回复...谢谢

I am having trouble finding the answer to this question, I''m thinking
the solution must be blindingly obvious, so therefore of course I
cannot see it.

I wish to take a fraction in DEC say .4 and convert it to a HEX value.
I also need to find a way to determine if a number is a fraction in
HEX and convert it back to DEC.

(This would be from a disassembly, and we are learning this for
troubleshooting purposes)

My instructor showed us this, but he has got to be the most boring
person on earth and to be honest I think I dozed off for a second. I
really want to be a proffesional computer programmer, and nothing
about this is listed in the book. But we have a homework assignment
and I have 3 days to get this done. There is a list of 50 numbers in
both HEX and DEC. I won''t list them here cuz I want to solve the
problems myself, I just happen to need to be pointed in the right
direction for solving them, a formula or something would be nice.

BTW I have tried the calc.exe HEX function, and when I select .4 then
switch to HEX I get 0, which I know cannot be the right answer (does
explain alot of problems with windows though :)

I know that the problem is related to disassembly, but the course is
C++ so I''m really hoping to not got flamed for an irrelevant post.

Thank you in advance for your replies... BTW the email is made up, so
only reply here... Thank you

推荐答案



史蒂夫 < GR ********* @ yahoo.com>在消息中写道

news:bb ************************** @ posting.google.c om ...

"Steve" <gr*********@yahoo.com> wrote in message
news:bb**************************@posting.google.c om...
我无法找到这个问题的答案,我在想
解决方案必须非常明显,因此我当然无法看到它。

我希望DEC中的一小部分说.4并将其转换为HEX值。
我还需要找到一种方法来确定数字是否是HEX中的分数并将其转换回DEC。

(这将来自拆卸,我们正在学习这个以便进行故障排除)

我的导师向我们展示了这个,但他必须成为地球上最无聊的人,说实话,我想我打瞌睡了一秒钟。我真的想成为一名专业的计算机程序员,书中没有列出任何关于此的内容。但我们有一个家庭作业
我有3天时间完成这项工作。在HEX和DEC中有一个包含50个数字的列表。我不会在这里列出它们因为我想自己解决问题,我恰好需要指出正确的方向来解决它们,一个公式或者某些东西会很好。

BTW我已经尝试了calc.exe HEX功能,当我选择.4然后
切换到HEX我得到0,我知道这不是正确的答案(确实是
虽然解释了很多与windows有关的问题:)

我知道这个问题与反汇编有关,但课程是C ++所以我真的希望不要因为无关紧要而受到抨击帖子。

提前感谢您的回复... BTW电子邮件已经完成,所以
只在这里回复...谢谢
I am having trouble finding the answer to this question, I''m thinking
the solution must be blindingly obvious, so therefore of course I
cannot see it.

I wish to take a fraction in DEC say .4 and convert it to a HEX value.
I also need to find a way to determine if a number is a fraction in
HEX and convert it back to DEC.

(This would be from a disassembly, and we are learning this for
troubleshooting purposes)

My instructor showed us this, but he has got to be the most boring
person on earth and to be honest I think I dozed off for a second. I
really want to be a proffesional computer programmer, and nothing
about this is listed in the book. But we have a homework assignment
and I have 3 days to get this done. There is a list of 50 numbers in
both HEX and DEC. I won''t list them here cuz I want to solve the
problems myself, I just happen to need to be pointed in the right
direction for solving them, a formula or something would be nice.

BTW I have tried the calc.exe HEX function, and when I select .4 then
switch to HEX I get 0, which I know cannot be the right answer (does
explain alot of problems with windows though :)

I know that the problem is related to disassembly, but the course is
C++ so I''m really hoping to not got flamed for an irrelevant post.

Thank you in advance for your replies... BTW the email is made up, so
only reply here... Thank you




这取决于您用于存储数字的表示形式,对于

示例浮点或固定点。然后,如果你选择浮点,

有很多种方法可以表示它们。现在,标准没有说b
说哪些必须使用,否则人们将不得不围绕该语言设计
硬件!

计算没有显示答案的原因是因为十六进制几乎总是用于显示整数的
,尽管没有理由它不能用于任何事情的
否则因为它只是二进制的简短表示。

所以简短的回答是,你必须自己编程。

Allan



This depends on which representation you use for storing numbers, for
example floating point or fixed point. Then if you choose floating point,
there are a number of ways of representing them. Now, the standard does not
say which of these have to be used, otherwise people would have to designt
hardware around the language!
The reason for calc not showing you the answer is because hex is almost
always used for displaying integers, although there is no reason it can''t be
used for anything else as it is just a short-hand representation for binary.
So the short answer is, you will have to program your own.
Allan


2004年4月14日22:54:15 -0700 comp.lang.c ++, gr*********@yahoo.com

(史蒂夫)写道,
On 14 Apr 2004 22:54:15 -0700 in comp.lang.c++, gr*********@yahoo.com
(Steve) wrote,
BTW我已经尝试了calc.exe HEX功能,当我选择.4然后
切换到十六进制我得到0,我知道这不是正确的答案(确实解释了很多关于Windows的问题:)
BTW I have tried the calc.exe HEX function, and when I select .4 then
switch to HEX I get 0, which I know cannot be the right answer (does
explain alot of problems with windows though :)




很多人显然认为基础有一些东西16,

使它仅适用于整数,与基数10不同。至少你已经领先了

。好吧,我会怜悯你的困境,即使我没有在你的问题中看到任何有关C ++的内容。不要让它

再次发生。


在十进制数字0.wxyz中,''w''是十分之一的数字,'' x''是百分之几的

,'''是千分之一的数字,而z是百万分之一的$ / b $ b。


如果它是十六进制,''w'是十六分之一,''x''是

数1 /(16 * 16)即256ths ,''y'是1 /(16 * 16 * 16)或

4096ths的数字,''z'是1 /(16 ^ 4)或65536ths的数字。


那么,16位是多少,小数是0.40,余数是多少?

余数是多少256?等等。


你可能会看到与C ++代码相关的十六进制分数,如果你转换
float或以十六进制加倍数。



A lot of people apparently think there is something about base 16 that
makes it apply only to integers, unlike base 10. At least you are ahead
of them. OK, I will take pity on your plight, even though I failed to
see anything whatsoever regarding C++ in your question. Don''t let it
happen again.

In a decimal number 0.wxyz the ''w'' is the number of tenths, ''x'' is the
number of hundredths, ''y'' is the number of thousandths, and z is the
number of ten thousandths.

If it was a hexadecimal, ''w'' is the number of sixteenths, ''x'' is the
number of 1/(16*16) i.e 256ths, ''y'' is the number of 1/(16*16*16) or
4096ths, and ''z'' the number of 1/(16^4) or 65536ths.

So, how many 16ths is 0.40 decimal, and what is the remainder?
How many 256ths is the remainder? And so on.

You might be likely to see hex fractions related to C++ code if you dump
float or double numbers in hex.


2004年4月14日星期三22:54:15 +0000,Steve写道:
On Wed, 14 Apr 2004 22:54:15 +0000, Steve wrote:
我无法找到回答这个问题,我在想
解决方案必须非常明显,所以我当然不能看到它。

我希望在DEC中占一小部分说.4并将其转换为HEX值。我还需要找到一种方法来确定一个数字是否是HEX中的分数
并将其转换回DEC。


[snip]

我不会在这里列出它们因为我想自己解决问题,我只是偶尔需要指向正确的方向来解决它们,
公式或其他东西会很好。
I am having trouble finding the answer to this question, I''m thinking
the solution must be blindingly obvious, so therefore of course I cannot
see it.

I wish to take a fraction in DEC say .4 and convert it to a HEX value. I
also need to find a way to determine if a number is a fraction in HEX
and convert it back to DEC.
[snip]
I won''t list them here cuz I want to solve the problems myself, I just
happen to need to be pointed in the right direction for solving them, a
formula or something would be nice.




有一个简单的算法可以用来转换分数。我可以

给你算法,所以你可以自己实现ist。


100将数字乘以你要转换的基数

200取大于1的数字,并将其用作转换后数字中的下一位数

300丢弃任何大于1的数字

400重复直到满意或留下零


示例:

..4 * 16 = 6.4(结果0.6)

..4 * 16 = 6.4(结果0.66)

....

示例2:

0.21875 * 16 = 3.5(结果0.3)

0.5 * 16 = 8(结果0.38)

完成


当你弄清楚分数是如何工作的,它应该相当容易

看看这个算法是如何工作的。

直到


-

请添加Salt and Peper到主题行绕过我的垃圾邮件过滤器



There is a simple algorithm you can use for conversion of fractions. I can
give you the algorithm, so you can implement ist for yourself.

100 multiply the number by the base you are converting to
200 take the number greater than one, and use it as the
next digit in your converted number
300 discard anything greater than one
400 repeat until satisfied or left with zero

Example:
..4 * 16 = 6.4 (result 0.6)
..4 * 16 = 6.4 (result 0.66)
....
Example 2:
0.21875 * 16 = 3.5 (result 0.3)
0.5 * 16 = 8 (result 0.38)
done

When you have figured out how fractions work, it should be fairly easy to
see how this algorithm works.
Till

--
Please add "Salt and Peper" to the subject line to bypass my spam filter


这篇关于如何在HEX中表示分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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