[英]Negative number binary and change LSB of it
Sir I have a problem.I find the binary of a negative number that gives me in 32 bits.I trim all other bits except the first 8 bits.Now I change LSB of it.It gives me 125 as answer. 先生,我有一个问题,我找到一个负数的二进制数给我32位,除前8位外我都修整了所有其他位,现在我更改了它的LSB,它给了我125。 I have to embed this in an gray scale image.
我必须将其嵌入灰度图像中。 According to my requirement , I have to add this 125 in mean(sum of four neighbouring pixels) .When i add this to mean.I gives me answer that exceeds 255. So is it posible that after modifing lsb.
根据我的要求,我必须在均值(四个相邻像素的总和)中添加此125。当我将其添加到均值时。我给我的答案超过了255。所以修改lsb之后是可能的。 my bit remain negative.
我的观点仍然是负面的。
here is my code 这是我的代码
string str1 = Convert.ToString(d[1, 1], 2);
str1 = str1.Substring(Math.Max(str1.Length - 8, 0)).PadLeft(8, '0');
char[] data = new char[str1.Length];
for (int m = 0; m < str1.Length; m++)
{
data[m] = str1[m];
}
//data[0] = '0';
string s="";
data[0] = '0';
for (int m = 0; m < str1.Length; m++)
{
s += data[m];
}
byte output = Convert.ToByte(s, 2);
Your code is trimming all but the last 8 bits. 您的代码正在修剪除最后 8位以外的所有内容。 If you want to trim all but the first 8 bits, you should use str1.Substring(0, 8).
如果要修剪除前 8位以外的所有位,则应使用str1.Substring(0,8)。 And you are changing the MSB of the last 8 bits.
并且您正在更改最后8位的MSB。 if you want to change the LSB, you should use data[7] instead of data[0].
如果要更改LSB,则应使用data [7]而不是data [0]。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.