How can we convert negative double value to binary value in matlab?

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 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 2 月 3 日
No inbuilt function. "float2bin" user defined function you may search.
Su Latt Sandi
Su Latt Sandi 2018 年 2 月 3 日
Thank for your answer:)
Rik
Rik 2018 年 2 月 3 日
How would you want to convert values to binary? For positive integers this is obvious (and you can use the built in dec2bin), but for all other values it isn't. double and single are already floats, and have a binary representation, but I don't see how that would benefit you for XOR. If you describe what shape the output should have, we can help you.
Su Latt Sandi
Su Latt Sandi 2018 年 2 月 3 日
I used "num2bin(q,x)" commend.But now, I can't xor with audio coefficients and key because dimension is different. I used "scramble=bitxor(c,k)" where c is coefficents(binary values) and k is key(binary value). The problem is c has 26656-row 64-column and k has 1-row 64-column. I can't xor and I don't know how can i get scramble value.
Su Latt Sandi
Su Latt Sandi 2018 年 2 月 4 日
Hi Sir, please find attachment
Walter Roberson
Walter Roberson 2018 年 2 月 4 日
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.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 3 日

0 投票

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.

その他の回答 (1 件)

Matt J
Matt J 2018 年 2 月 3 日
編集済み: Matt J 2018 年 2 月 3 日

1 投票

Use BITGET, for example,
>> bitget(-25,1:8,'int8')
ans =
1 1 1 0 0 1 1 1

1 件のコメント

Walter Roberson
Walter Roberson 2018 年 2 月 3 日
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.

サインインしてコメントする。

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by