--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
"krollenhagen" <v...@nospam.rollenhagen.us> wrote in message
news:17EE96A9-8EEE-4832...@microsoft.com...
> Hello-
>
> I am trying to take the 2s complement of a number. I have converted the
number into a binary string and then negated the string using if..then
statements. I can then convert this into a decimal value easily enough.
>
> I am wondering if there is an easier way to do this?
>
> Just wondering,
>
> Keith
"Two's complement" is simply numeric negation. For instance: lX2Complement
= -lX (where lX might be a Long variable)
Also,"One's completion" is simply bitwise inversion. For instance :
lX1Complement = Not lX
Tony Proctor
Maybe I'm being really dim, but if you're starting with a decimal number
and ending with a decimal number, are you trying to do anything
different than multiply the number by (-1) ?
Perhaps your problem is something to do with the length of the number in
bits.
If you need to manipulate the bits directly, look at the Not operator
--
Steve Garman
Private Function CheckSum(TheString As String, TheLength As Integer) As
String
Dim TempCheckSum As Integer
Dim i As Integer
For i = 1 To TheLength
TempCheckSum = (TempCheckSum + Asc(Mid$(TheString, i, 1))) And &HFF
Next i
CheckSum = Chr$((-TempCheckSum) And &HFF)
End Function
I seem to remember returning a string since I was just appending it the
TheString.
Thanks for all your help. I got it working.
Keith