# Thread: How to do ones compliment

1. ## 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,
};```

2. ## 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).

#### Posting Permissions

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