How can we convert negative double value to binary value in matlab?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Su Latt Sandi
am 3 Feb. 2018
Kommentiert: Walter Roberson
am 4 Feb. 2018
I'm the student of UCSY.I research for audio scrambling. In my research, I need to scarmble audio data with key using bit wise xor.Now,I have difficulties to convert negative float value to binary value to scramble. Please, anyone can help me?? I would be grateful if someone help me in this matter.
6 Kommentare
Walter Roberson
am 4 Feb. 2018
num2bin() is for Fixed Point Objects, not for general numbers.
num2bin returns characters, so subtract '0' (the character for the digit 0) to get the numeric values.
Akzeptierte Antwort
Walter Roberson
am 3 Feb. 2018
If you are reading the audio data from a file, I recommend that you add the 'native' option. That would usually result in the data being read in as integer, which you can then manipulate.
Otherwise, easiest is probably to typecast() the floating to integer form.
0 Kommentare
Weitere Antworten (1)
Matt J
am 3 Feb. 2018
Bearbeitet: Matt J
am 3 Feb. 2018
Use BITGET, for example,
>> bitget(-25,1:8,'int8')
ans =
1 1 1 0 0 1 1 1
1 Kommentar
Walter Roberson
am 3 Feb. 2018
That only works for values that are integers.
You can experiment with
bitget(typecast(-25.2, 'uint64'), 1:8)
but beware that the byte order might not be what you are expecting.
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing 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!