简体   繁体   English

如何将有符号的 16 位十六进制转换为十进制?

[英]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.

相关问题 如何在R中转换64位十六进制字符串? - How do I convert 64-bit hexadecimal strings in R? 在 R 中将 32 位浮点栅格转换为 16 位 - Convert 32-bit float raster to 16-bit in R 传递具有缺失值的向量时,如何将 R 中的大十六进制值转换为十进制值? - How do you convert large hexadecimal values to decimal values in R when passing a vector with missing values? 在 R 中使用 magick package 从 16 位 tiff 图像中获取像素值 - Obtaining pixel value from 16-bit tiff images using magick package in R 如何将 16 位 TIFF 读入 R 并保留像素强度,以便我可以使用 EBImage package 将其用作带标签的 object 掩码? - How do I read in a 16bit TIFF into R and preserve pixel intensities, so that I can use it as a labelled object mask using the EBImage package? 如何在r的矩阵中将十六进制转换为二进制? - How to convert hexadecimal to binary in a matrix in r? 如何将时间转换为十进制 - How to convert time to decimal 如何在R中将度分秒转换为十进制? - How can I convert Degree minute sec to Decimal in R? 如何将包含十进制数的因子列转换为数字? - How can i convert a factor column that contains decimal numbers to numeric? 如何将十进制度分转换为十进制度 - How to convert degrees decimal minutes, to decimal degrees
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM