Results 1 to 2 of 2

Thread: How to do ones compliment

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    How to do ones compliment

    I have the below table in C that I need to convert to VB and the ~ means ones compliment

    Code:
    int const s_argcf[] =
    {
      ~cfE1C1,~0,~0,~0,~(cfE1G1 | cfE1C1),~0,~0,~cfE1G1,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~0,~0,~0,~0,~0,~0,~0,~0,
       0, 0, 0, 0, 0, 0, 0, 0,
      ~cfE8C8,~0,~0,~0,~(cfE8G8 | cfE8C8),~0,~0,~cfE8G8,
       0, 0, 0, 0, 0, 0, 0, 0,
    };


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,116

    Re: How to do ones compliment

    Well, technically all the ~0's become -1.
    or just replace all the ~ with Not, i.e ~0 becomes Not 0

    You could also Xor with -1, but that is bulkier than just doing Not.

    Code:
    Dim b as Long
    Dim x as Long
    x = -1
    b = 0
    Debug.Print Not b
    Debug.Print b Xor x
    should both show -1 as the result.

    If b was 1, then both should show -2 as the result.

    b = -b is doing a two's complement.
    so you can also convert a two's complement into a one's complement by adding 1 to the number first.
    b = -(b + 1)

    Using Not should be the fastest, followed by Xor with -1, followed by negating (number + 1).
    Last edited by passel; Dec 23rd, 2014 at 03:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width