将十进制数转换为16位温度二进制。

huangapple go评论67阅读模式
英文:

Converting decimal number to 16 bit temperature binary

问题

我有一个关于转换的问题。
在关于DS18B20温度传感器的文档中,我需要将18.25摄氏度转换为二进制。
有人能解释一下如何做吗。
将十进制数转换为16位温度二进制。

我尝试在互联网上寻找答案,但我找不到类似的东西。

英文:

I have a question about conversion.
In a document about DS18B20 temperature sensor i need to convert 18.25C to binary.
Can someone explain how to do it.
将十进制数转换为16位温度二进制。

I tried looking for answers on the internet but i can't find anything similar.

答案1

得分: 0

看起来二进制值是以0.0635度为增量的十进制温度(0.5 = 0.0625*8 = 0008h10.125 = 0.0625*162 = 00A2h

所以18.25的转换为

18.25/0.0625 = 292 = 0124h = 0000 0001 0010 0010

或者,由于1/0.0625 = 16,你也可以通过乘以16来进行转换:

18.25 * 16 = 292 = 0124h = 0000 0001 0010 0010
英文:

It looks like the binary value is the decimal temperature in increments of 0.0635 degrees (0.5 = 0.0625*8 = 0008h, 10.125 = 0.0625*162 = 00A2h)

so the conversion for 18.25 would be

18.25/0.0625 = 292 = 0124h = 0000 0001 0010 0010

Or, since 1/0.0625 = 16, you could convert it by multiplying by 16:

18.25 * 16 = 292 = 0124h = 0000 0001 0010 0010

huangapple
  • 本文由 发表于 2023年5月11日 04:23:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222295.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定