如何将负数转换为二进制,反之亦然?

时间:2017-07-15 23:44:39

标签: c++ audio binary bitset wave

我有这个音频文件,我将它的音频值转换为二进制数,以便我将它们隐藏在图像像素中。

我用来转换音频值的是bitset< 16>因为音频值存储在short int变量中。

转换为二进制文件的效果很好,即使它是负数但从负二进制值到十进制的转换不起作用,所以任何人都知道将负二进制数转换为十进制的合适方法。

bitset <16>a = -8;
cout<<a<<endl;
output = 1111 1111 1111 1000

bitset <16>b = 8;
cout<<b<<endl;
output = 0000 0000 0000 1000
// but if i tried to convert the binary that i got earlier from the -8
bitset <16> c = 1111111111111000;
cout<< c.to_ulong()<<endl;
output = 29016
// how can i get the output of -8 from the c?  

0 个答案:

没有答案