How do I convert a signed 16-bit hexadecimal to decimal?

1.7k views Asked by At

I have a very long sequence of data stored as unsigned 16-bit PCM (it's audio). Using Frhed, I can view the file as hex. 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(). However, this doesn't seem to take into account that the values are signed.

1

There are 1 answers

0
G5W On

You can convert hex text strings to decimal digits using strtoi. You will need to specify that the base is 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.