Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting an array of 16-bit signed numbers to postive & negative

Status
Not open for further replies.

Littlestar

Technical User
Jun 2, 2004
3
CA
How do I sort an array0 of 16-bit signed numbers to arrays of positive & negative numbers so that Im able to print out something like this? Thanks.

array0: -10 566 0 -99 12345 -54321
array1: 566 0 12345
array2: -10 -99 -54321
 
First: Know that a negative number's topmost bit is set, while a positive number's topmost bit is cleared

Second: Know just WHAT size your numbers are. -54321 is IMPOSSIBLE for a 16-bit number. Are you sure about that?

Third: The topmost bit of a 16-bit integer is the 15th bit. Whose value is... 2 to the 15th of course!

Fourth: The TEST instruction is used to test whether or not a bit is set or cleared. So you test that bit.

Fifth: NOW you know whether it's negative or positive! BUT: Where are you gonna place that number?

Sixth: Have three indexes: one for array1, one for array2, and one for array3.

Seventh: Good luck and have fun. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Thanks AmkG.
I have wrote out the program and its working. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top