Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
How to 2s complement
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jonathan Wood  
View profile  
 More options Jun 29 2004, 1:26 pm
Newsgroups: microsoft.public.vb.general.discussion
From: "Jonathan Wood" <jw...@softcircuits.com>
Date: Tue, 29 Jun 2004 11:26:32 -0600
Local: Tues, Jun 29 2004 1:26 pm
Subject: Re: How to 2s complement
You can obtain the two's complement of a value by subtracting the value from
0.

--
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-BEF1-57533DC452CA@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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Proctor  
View profile  
 More options Jun 29 2004, 1:29 pm
Newsgroups: microsoft.public.vb.general.discussion
From: "Tony Proctor" <tony_proctor@aimtechnology_NOSPAM_.com>
Date: Tue, 29 Jun 2004 18:29:13 +0100
Local: Tues, Jun 29 2004 1:29 pm
Subject: Re: How to 2s complement
You don't need to do all that 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

"krollenhagen" <v...@nospam.rollenhagen.us> wrote in message

news:17EE96A9-8EEE-4832-BEF1-57533DC452CA@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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Garman  
View profile  
 More options Jun 29 2004, 1:42 pm
Newsgroups: microsoft.public.vb.general.discussion
From: Steve Garman <n...@garman.demon.co.uk>
Date: Tue, 29 Jun 2004 18:42:21 +0100
Local: Tues, Jun 29 2004 1:42 pm
Subject: Re: How to 2s complement

krollenhagen wrote:
> 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

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
krollenhagen  
View profile  
 More options Jun 29 2004, 1:48 pm
Newsgroups: microsoft.public.vb.general.discussion
From: krollenhagen <v...@nospam.rollenhagen.us>
Date: Tue, 29 Jun 2004 10:48:02 -0700
Local: Tues, Jun 29 2004 1:48 pm
Subject: Re: How to 2s complement
Thank you.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doug  
View profile  
 More options Jun 29 2004, 1:51 pm
Newsgroups: microsoft.public.vb.general.discussion
From: "Doug" <non...@noaddress.com>
Date: Tue, 29 Jun 2004 10:51:34 -0700
Local: Tues, Jun 29 2004 1:51 pm
Subject: Re: How to 2s complement
I don't know if this applies to you but here's a little function I wrote
years ago to to take the 2's complement of the Mod 256 sum of the data bytes
in the string if interest....

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.

"krollenhagen" <v...@nospam.rollenhagen.us> wrote in message

news:17EE96A9-8EEE-4832-BEF1-57533DC452CA@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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
krollenhagen  
View profile  
 More options Jun 29 2004, 4:10 pm
Newsgroups: microsoft.public.vb.general.discussion
From: krollenhagen <v...@nospam.rollenhagen.us>
Date: Tue, 29 Jun 2004 13:10:03 -0700
Local: Tues, Jun 29 2004 4:10 pm
Subject: Re: How to 2s complement
I am calculating the BCC error correction byte and having to tack that on to the end of the string that I am sending out on the serial port.

Thanks for all your help.  I got it working.

Keith


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »