简单的十六进制到十进制转 [英] Simple hex to decimal conversion

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

问题描述

Option Strict On
Imports System.IO.Ports

    Dim q As Queue(Of Byte) = New Queue(Of Byte)

    Private Sub SerialPort1_DataReceived(ByVal sender As Object,
        ByVal e As SerialDataReceivedEventArgs) _
        Handles SerialPort1.DataReceived
        While SerialPort1.BytesToRead > 0
            q.Enqueue(CByte(SerialPort1.ReadByte))
        End While
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
        SyncLock q
            While q.Count > 0
                Dim B As Byte = q.Dequeue
                tbRx.Text &= Hex(B) & " "
            End While
        End SyncLock
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnStop.Click
        SerialPort1.Close()
        Timer1.Stop()
    End Sub



不是完整代码

如果温度是21.3摄氏度,则在tbRx中elsius,我看到4 BD的值。但是我想要另一个给出十进制值的文本框(从那里我可以将其转换为温度)。



我尝试了什么: < br $>


i尝试了类似Textbox1.text = B

但这是绝对错误的。


NOT FULL CODE
In tbRx if the temperature is something like 21.3 degrees celsius, I see a value of 4 BD. However I want another textbox giving the decimal value( from there i can then convert that to temperature).

What I have tried:

i have tried something like Textbox1.text = B
but that is hopelessly wrong.

推荐答案

从你的温度计发出的值是什么格式来看并不明显:4 BD中最简单的转换4BD Hex == 1213 Dec暗示它可能是℃C加100倍10但是从一个样本中你无法可靠地推断出来。



所以请与制造商联系(或者至少查看他们的网站上的文档),看看他们是否确切地解释了什么是被发送以及如何转换。

我们不能为你做到这一点!
It's not obvious from that what format the values coming from your temperature gauge are being sent in: 4 BD in it's simplest conversion 4BD Hex == 1213 Dec which implies it might be "degrees C plus 100 times 10" but from one sample you can't reliably infer that.

So talk to the manufacturer (or at least check their website for documentation) and see if they explain exactly what is being sent and how it should be converted.
We can't do that for you!


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

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