Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

2's complement in VB

  1. Jan 19, 2007 #1
    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?

  2. jcsd
  3. Jan 19, 2007 #2


    User Avatar
    Science Advisor

    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 (Text):

    int b = 230;
    int bAfter2sC = ~b + 1
    In VB.Net try:
    Code (Text):

    Dim b As Integer
    Dim bAfter2sC As Integer
    bAfter2sC = Not(b) + 1
    Last edited: Jan 19, 2007
  4. Jan 19, 2007 #3
    thank you very much again!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: 2's complement in VB
  1. VB Problem (Replies: 0)

  2. Help with VB (Replies: 1)

  3. Method of Complements (Replies: 3)