Get bits of number.
64 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Raldi
am 13 Apr. 2015
Bearbeitet: Guillaume
am 13 Apr. 2015
I have a 16 bit double I got from using wavread that I want to get the first 8 bits from.
As an example lets say I have 67. Inside my computer it must be represented as a series of bits, 0111001 in this case. So lets say that I just want to have the last for of them 1001.
How can this be done?
3 Kommentare
Guillaume
am 13 Apr. 2015
Also, 67 in binary is not 00111001:
>>dec2bin(67, 8)
ans = 0100011
Akzeptierte Antwort
Guillaume
am 13 Apr. 2015
n = hex2dec('AF75'); %for example, bit pattern is 1010 1111 0111 0101.
bitpattern = bitget(n, 1:8, 'uint16')
returns
bitpattern =
1 0 1 0 1 1 1 0
2 Kommentare
Guillaume
am 13 Apr. 2015
Bearbeitet: Guillaume
am 13 Apr. 2015
I'm not sure when the type specifier was added to bitget, I think it's fairly recent.
On older versions of matlab, this should work:
n = hex2dec('AF75'); %for example, bit pattern is 1010 1111 0111 0101.
bitpattern = bitget(uint16(n), 1:8)
That is convert your number (of type double) to an unsigned integer type.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!