VB: 2's Complement on Byte - Function & Binary Conversion

  • Thread starter Thread starter ionlylooklazy
  • Start date Start date
AI Thread Summary
To perform a 2's complement operation on a byte, the process involves converting the byte or character to an integer, applying a bitwise NOT operation, and then adding 1. In C#, this can be achieved using the bitwise NOT operator (~) followed by addition. For example, if the byte value is 230, the operation would be implemented as `int bAfter2sC = ~b + 1`. Similarly, in VB.Net, the operation can be executed with `bAfter2sC = Not(b) + 1`. This method effectively allows for the conversion of a byte to its 2's complement representation.
ionlylooklazy
Messages
30
Reaction score
0
is there a function available that will perform 2's complement on a byte?
or a way to convert a byte or char to binary so I can do the operation myself?

thanks,
ioll
 
Technology news on Phys.org
It should be pretty simple. All you need to do is perform a bitwise NOT and then add a 1. You would convert your byte or char to an Int, perform the bitwise Not, and then add a 1. In C# the ~ is the bitwise NOT, so you would do:
Code:
int b = 230;
int bAfter2sC = ~b + 1

In VB.Net try:
Code:
Dim b As Integer
Dim bAfter2sC As Integer
bAfter2sC = Not(b) + 1
 
Last edited:
thank you very much again!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Back
Top