I am doing some work with MemoryBlocks and integers, and am getting different results from ‘Not 0’ when I use a MemoryBlock or when using an integer. Not zero in an integer of 1 is zero, while Not Zero of a memoryblock is 1111111111111111111111111111111111111111111111111111111111111110.
I understand that the One’s complement of the memory block should be 1111…etc…1111, and the last digit should probably be a 1 instead of a zero to have the number -0… am I correct, or did I mess up some code?..
Here is the code for using not 1 with an integer:
[code]Sub Action() Handles Action
//Create 2 integer variables
Dim X, Z as Integer
//Populate X with binary text data
X = Val("&b" + TFX.Text)
//Calculate Bit AND result
Z = Not X
//Show Bit Not result
LblAnswer.Text = Z.ToBinary
End Sub
[/code]
Here is the code for using not 1 with a MemoryBlock:
[code]Sub Action() Handles Action
//Create a MemoryBlock Variable
//64 bytes * 8 bits/byte = 512
Dim X as New MemoryBlock(512)
//Populate X with binary text data
X.UInt64Value(0) = Val("&b" + TFX.Text)
//Calculate Bit XOR result
Dim Z as New MemoryBlock(512)
Z.UInt64Value(0) = Not X.UInt64Value(0)
//Show Bit XOR result
LblAnswer.Text = Z.UInt64Value(0).ToBinary
End Sub
[/code]
Instinctively, Id say both these responses are wrong, although I can see how you might defend
Not 0 == 1
If doing a true NOT at a bit level,
Not 0 should get you a string of 1s as wide as the integer storage
So at bit level, you get 1
At byte level you get 11111111
and so on… but everything that was 0 should be 1
Your right that the comments were misleading. I was calculating NOR and AND to make sure that those functions worked and I forgot to update the comments. Thanks for mentioning it.
Just an added note for the logic clarity behind this question. I made a presumption in believing that because the integer value of ‘not 1 = 0’, then the binary value of 'not 0001 should mistakenly be ‘0000’ (binary representation of an integer), and instead the program correctly had the value of ‘not 0001 is 1110’