如何将十六进制值的二进制数组转换为十进制字符串 [英] how to convert a binary array with hex values into decimal string

查看:96
本文介绍了如何将十六进制值的二进制数组转换为十进制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含十六进制值的字节数组。我想将其6个字节转换为十进制值,并将结果显示为字符串。


我什么时候必须考虑结束?


i试图基本上直接分配到unsigned long我看到了它确实正确地转换它但我没有使用任何endianess。虽然我仍然没有把它转换为字符串。


我什么时候使用endianess(我在unbuntu上开发但我知道我必须将它移植到sun box / hp box也许)。我确实读过某个地方,只要无符号长尺寸<= 2它就可以在任何方框上工作。这是真的?如果是这样的原因?


您的帮助将不胜感激。

i have a byte array that contains hex values. i want to convert 6 bytes of it into decimal values and display the result as a string.

also when do i have to take the endianess into consideration?

i have tried to basically do a direct assignment to unsigned long and i saw that it did convert it correctly but i did not use any endianess. although i still did not convert it into a string.

when do i use endianess ( i am developing on unbuntu but i know i will have to port this to a sun box/hp box maybe). i did read somewhere that as long as the unsigned long size is <= 2 it should work on any box. is this true? if so why?

your help would be greatly appreciated.

推荐答案

BTW我不使用.net c ++所以我不能使用bitconverter等。
BTW i am not using .net c++ so i cannot use bitconverter etc.


展开 | 选择 | Wrap | 行号


我认为你不必担心除非您执行以下操作之一,否则将使用字节顺序:
  • 您的程序有时会通过一种类型访问相同的数据项,有时也会通过另一种不同大小的类型访问相同的数据项。例如,您有一个32位数据项有时作为无符号长整数访问,有时作为无符号字符数组访问。
  • 您试图访问一个必须也可以访问的数据项系统;也就是说,系统不能保证是相同的处理器和编译器组合。例如,您的PC正在写入可能由Linux PC读取的二进制文件。
  • 您正在访问内存映射的I / O设备。
I don''t think you need to worry about endianness unless you''re doing one of the following:
  • Your program accesses the same data item sometimes via one type and sometimes via another, differently sized, type. For example, you have a 32-bit data item that is sometimes accessed as an unsigned long and sometimes as an array of unsigned chars.
  • You seek to access a data item that must also be accessible to a dissimilar system; that is, a system that is not guaranteed to be the same processor and compiler combination. For example, your PC is writing to a binary file that might be read by a Linux PC.
  • You are accessing memory-mapped I/O devices.


这篇关于如何将十六进制值的二进制数组转换为十进制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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