[英]How do I convert a signed 16-bit hexadecimal to decimal?
I have a very long sequence of data stored as unsigned 16-bit PCM (it's audio).我有很长的数据序列存储为无符号 16 位 PCM(它是音频)。 Using Frhed, I can view the file as hex.
使用 Frhed,我可以将文件查看为十六进制。 I'd like to convert the hex into decimal.
我想将十六进制转换为十进制。 So far I've exported into a csv file and attempted to convert in R using
as.integer()
.到目前为止,我已经导出到一个 csv 文件并尝试使用
as.integer()
在 R 中进行转换。 However, this doesn't seem to take into account that the values are signed.但是,这似乎没有考虑到这些值是有符号的。
You can convert hex text strings to decimal digits using strtoi
.您可以使用
strtoi
将十六进制文本字符串转换为十进制数字。 You will need to specify that the base is 16.您需要指定基数为 16。
HexData = c("A167", "AE8F", "6A99", "0966", "784D", "A637", "102D", "4521")
strtoi(HexData, base=16L)
[1] 41319 44687 27289 2406 30797 42551 4141 17697
This is assuming unsigned data.这是假设未签名的数据。 Your question mentions both signed and unsigned so I am not quite sure which you have.
你的问题提到了签名和未签名,所以我不太确定你有哪个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.