这是什么类型的编码 [英] What type of encoding is this

查看:57
本文介绍了这是什么类型的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Good Afternoon



我正在尝试使用以下编码读取txt文件:& 3f9c9aaa



这转换为:92.35

在它使用的程序中。



我试图读取这个值并将其发布在记分牌式系统。

任何帮助都会很友好



谢谢



我尝试过:



向编程朋友询问。谷歌搜索的东西,如十六进制,二进制和汇编

Good Afternoon

I am trying to read a txt file with the following encoding: &3f9c9aaa

This converts to: 92.35
In the program it uses.

I am trying to read this value and post it on a scoreboard type system.
Any help would be kind

Thanks

What I have tried:

Asking programming friends. Googling stuff like hex, binary and assembly

推荐答案

我想知道它是否简单(抱歉,c#)



I wonder if its as simple as (sorry, c#)

string hexString = "43480170";
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);

byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
Console.WriteLine("float convert = {0}", f);

// Output: 200.0056   

如何:在十六进制字符串和数字之间转换的


类型(C#编程指南) [ ^ ](第4个例子)



from How to: Convert Between Hexadecimal Strings and Numeric Types (C# Programming Guide)[^] (4th example down)


大家好



只是为了更新任何未来搜索此问题的用户

我设法解决了它。

它的单精度浮点

IEEE 754



这是我使用的代码

这个:& 433d7bc4

翻译为189.48346



Hi All

Just to update any future users searching for this issue
I managed to solve it.
its a single precision floating point
IEEE 754

Here is the code i used
this: &433d7bc4
Translates to 189.48346

Private Function ConvertHexToSingle(hexVal As String) As [Single]
    Try
        Dim i As Integer = 0, j As Integer = 0
        Dim bArray As Byte() = New Byte(3) {}
        'Dim new as String =

        For i = 0 To hexVal.Length - 1 Step 2
            bArray(j) = [Byte].Parse(hexVal(i).ToString() + hexVal(i + 1).ToString(), System.Globalization.NumberStyles.HexNumber)
            j += 1
        Next
        Array.Reverse(bArray)
        Dim s As [Single] = BitConverter.ToSingle(bArray, 0)
        Return (s)
    Catch ex As Exception
        Throw New FormatException("The supplied hex value is either empty or in an incorrect format. Use the " + "following format: 00000000", ex)
    End Try
End Function


这篇关于这是什么类型的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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