How do I convert a column in an array that have 18-bit singed integer to 32-bit?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Steven Settle
am 25 Apr. 2022
Kommentiert: Walter Roberson
am 29 Apr. 2022
I have an array with time and data that I'm trying to plot, but the problem I'm running into is that the data is a 18-bits signed. What is the best way to convert the 18-bit signed data to 32-bit signed data that can be easily processed?
I have tried converting it to a binary string and then using something like b=[a([1 1 1 1 1 1 1 1 1 1 1 1 1 1]) a] where "a" is 18 bit long binary string, and then converting it back to int32 with k = typecast(uint32(bin2dec(b)),'int32'); , but I'm not sure how to do this for a whole array. Could I use cellfun somehow? Is there a better way to approach this?
3 Kommentare
Walter Roberson
am 29 Apr. 2022
S = '0X7FC48';
bit18 = sscanf(S, '%i')/2
bit18bin = dec2bin(bit18, 18)
N = 18;
mask = bit18>=2^(N-1)
bit32 = bit18
bit32(mask) = bit32(mask) - 2^N
dec2bin(-480, 18)
Your example does not represent -480, it represents -476
Akzeptierte Antwort
Walter Roberson
am 25 Apr. 2022
N = 18;
mask = bit18>=2^(N-1);
bit32 = bit18;
bit32(mask) = bit32(mask) - 2^N;
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!