将float转换为单个字节 [英] converting float to individual bytes

查看:168
本文介绍了将float转换为单个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯用c或c ++编程,我的问题很简单。


我希望能够在页面上输入一个值(比如3.2),然后把它读成

它作为32位浮点数并将其分解为它的单个字节。

我尝试过使用按位运算符,但它们似乎首先将值

转换为整数,并且我尝试使用toString()方法将
转换为十六进制值,以便我可以解析它,但是这似乎也是

首先将其转换为整数。


任何帮助都会非常感激。

I''m used to programming in c or c++ in which my problem is simple.

I want to be able to enter a value on a page (like 3.2), and then read
it as a 32-bit float and break it into it''s individual bytes.
I''ve tried using bitwise operators, but they seem to convert the value
into an integer first, and i''ve tried using the toString() method to
convert it into a hex value so i can parse it, but that also seems to
first convert it into an integer.

any help would be much appreciated.

推荐答案

TK于2005年6月3日在comp.lang.javascript中写道
TK wrote on 03 jun 2005 in comp.lang.javascript:
我习惯于在c编程或者我的问题很简单的c ++。

我希望能够在页面上输入一个值(比如3.2),然后把它读成32位浮点数并打破它进入了它的个别字节。
我试过了usi按位运算符,但它们似乎首先将值转换为整数,并且我尝试使用toString()方法将其转换为十六进制值,以便我可以解析它,但是这似乎也首先将它转换为整数。

任何帮助都会非常感激。
I''m used to programming in c or c++ in which my problem is simple.

I want to be able to enter a value on a page (like 3.2), and then read
it as a 32-bit float and break it into it''s individual bytes.
I''ve tried using bitwise operators, but they seem to convert the value
into an integer first, and i''ve tried using the toString() method to
convert it into a hex value so i can parse it, but that also seems to
first convert it into an integer.

any help would be much appreciated.




请看一下非常明确的来源:


< http://babbage.cs.qc.edu/courses/cs341/IEEE-754hex32.html>


,所有人都会透露给你。


-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



Please look at the very explicit source of:

<http://babbage.cs.qc.edu/courses/cs341/IEEE-754hex32.html>

and all will be revealed to you.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


Evertjan。写道:
Evertjan. wrote:
TK于2005年6月3日在comp.lang.javascript中写道

TK wrote on 03 jun 2005 in comp.lang.javascript:

我是习惯用c或c ++编程我的问题很简单。

我希望能够在页面上输入一个值(比如3.2),然后把它读成
-bit浮动并将其分解为单个字节。
我尝试过使用按位运算符,但它们似乎首先将值转换为整数,并且我尝试过使用toString()方法将它转换为十六进制值,所以我可以解析它,但似乎首先将它转换为整数。

任何帮助都将是非常感谢。
I''m used to programming in c or c++ in which my problem is simple.

I want to be able to enter a value on a page (like 3.2), and then read
it as a 32-bit float and break it into it''s individual bytes.
I''ve tried using bitwise operators, but they seem to convert the value
into an integer first, and i''ve tried using the toString() method to
convert it into a hex value so i can parse it, but that also seems to
first convert it into an integer.

any help would be much appreciated.



请查看非常明确的来源:

< http://babbage.cs.qc.edu/courses/cs341/ IEEE-754hex32.html>

将全部透露给您。


Please look at the very explicit source of:

<http://babbage.cs.qc.edu/courses/cs341/IEEE-754hex32.html>

and all will be revealed to you.




看起来比我需要的要多得多。有没有更简单的方法?

我需要的是能够在屏幕上输入类似3.2的值,并且/ b $ b将每个字节分别显示为0x40 0x4C 0xCC 0xCC。 br />



that appears to do a lot more than I need. Is there a simpler way?
All I need is to be able to input a value like 3.2 on screen, and
display each byte seperatly as 0x40 0x4C 0xCC 0xCC.


TK于2005年6月3日在comp.lang.javascript中写道
TK wrote on 03 jun 2005 in comp.lang.javascript:
Evertjan。写道:
Evertjan. wrote:
TK于2005年6月3日在comp.lang.javascript中写道

TK wrote on 03 jun 2005 in comp.lang.javascript:

我是习惯用c或c ++编程我的问题很简单。

我希望能够在页面上输入一个值(比如3.2),然后把它读成
-bit浮动并将其分解为单个字节。
我尝试过使用按位运算符,但它们似乎首先将值转换为整数,并且我尝试过使用toString()方法将它转换为十六进制值,所以我可以解析它,但似乎首先将它转换为整数。

任何帮助都将是非常感谢。

请查看非常明确的来源:

< http://babbage.cs.qc.edu/courses/cs341/IEEE-754hex32。 html>

并且所有内容都将向您透露。
I''m used to programming in c or c++ in which my problem is simple.

I want to be able to enter a value on a page (like 3.2), and then read
it as a 32-bit float and break it into it''s individual bytes.
I''ve tried using bitwise operators, but they seem to convert the value
into an integer first, and i''ve tried using the toString() method to
convert it into a hex value so i can parse it, but that also seems to
first convert it into an integer.

any help would be much appreciated.
Please look at the very explicit source of:

<http://babbage.cs.qc.edu/courses/cs341/IEEE-754hex32.html>

and all will be revealed to you.



似乎比我需要的更多。有没有更简单的方法?



that appears to do a lot more than I need. Is there a simpler way?




但这不是你问的!

我只需输入一个像这样的值3.2在屏幕上,并将每个字节分别显示为0x40 0x4C 0xCC 0xCC。



But that is not what you asked!
All I need is to be able to input a value like 3.2 on screen, and
display each byte seperatly as 0x40 0x4C 0xCC 0xCC.




不可能,因为该格式只支持整数,并且定义

你想要的东西还不清楚。


这些字节代表什么,如果不是像babbage上的那么复杂

上面的网站?


-

Evertjan。

荷兰。

(用点替换所有十字架在我的电子邮件地址中)



Impossible, because that format only supports integers, and a definition
of what you compoundly want is not clear.

What would those bytes represent, if not a complicated as on the babbage
site above?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


这篇关于将float转换为单个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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