Go to Post I'm not gonna reinvent the wheel cause I can already buy it :) - Stephen Kowski [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-11-2002, 00:29
Steve Shade Steve Shade is offline
Registered User
no team
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1999
Location: Pasadena, MD
Posts: 78
Steve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud of
I'm just going to tackle a couple of these questions right now:

1) Two's complement is one of the ways represent negative numbers. Basically, the easy way to calculate the 2's complement of a number is to flip all the bits and add 1. the number (00110101) = 53 has a 2's complement of -53 = (11001011). However, in our world of P-BASIC, (11001011) = 203 because P-BASIC will display numbers as positive intergers only.
This form of a number is useful when you want to subtract numbers. If you want to do A-B = A + (2's complement of B) This is what most people use when they create digital circuitry, and what most (not all) computer processors use. My advise is to stay away from this unless you must because it can get very confusing very quickly.


5) I think i understand what you are asking because i've run into the same problem a numebr of times. Understand that a variable (in our case mostly bytes (8 bits) are loaded into the Arithmetic unit which uses 16 bits to perform calculations. So if we were to take a byte, in binary, (10011100) and perform ~(10011100) and then save it back ot the same place the basic process would look something like this:

varName = (10011100)
varName = ~varName

Description of the 2nd line of code:
1) 10011100 is loaded into the Arithmetic Unit and becomes (00000000 10011100)

2) this word (16 bits) is then inverted and becomes (11111111 01100011)

3) the word value (11111111 01100011) is truncated to a byte and the new value of varName = (01100011)

if you were using the ~ operator in the middle of a calculation then you were adding a whole lot of 1's to the front thus making your calculations not work, unless you saved back to a varriable.

There is a simple way to fix this. if you were to subtract off the leading 1's then you would get the answer you are loking for. So in the case of a byte, using the expression: (~varName - 65280) This means you can bitwise invert the number without having to save.

65280 = (11111111 00000000)



I hope this helps.

Steve
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I'll delete this in a couple of hours. hixofthehood Chit-Chat 9 04-02-2003 23:26
couple of questions... archiver 2001 5 23-06-2002 22:48
A couple of problems I observed at the MAR archiver 2000 3 23-06-2002 22:27
Couple other thank yous Jason Haaga Thanks and/or Congrats 0 29-04-2002 03:29
A Couple Questions about Chairman's Award ben_whly Chairman's Award 4 26-01-2002 18:24


All times are GMT -5. The time now is 04:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi