unsigned word to signed word in RB 
Author Message
 unsigned word to signed word in RB

I Have a value between 0-65535 and i need -32767 - (+32767)..I've
completely forgot how to do especially without bitwise operators... Can
anyone refresh my memory please?
Eli
--
If you build something from the inside out,
you'll have no difficulties penetrating from the outside in


Tue, 07 Oct 2003 10:29:56 GMT  
 unsigned word to signed word in RB

Quote:

>I Have a value between 0-65535 and i need -32767 - (+32767)..I've
>completely forgot how to do especially without bitwise operators... ?

RB Integers are designed as DWord (Long) values (4 bytes). So you aren't
going to be able to get this without some work.

You have 3 main options (that I see):

1) Perform the 2's compliment (bitwise operations)
--> Just do a BitwiseXOR on all bits and then add 1 to the result.

2) Check to see if the value is >32768. If so, convert it
--> -32667+(x-32768)

3) Use a MemoryBlock with 2 bytes in it.
--> mb.UShort(0)=x, x=mb.Short(0)

Hope this helps!
Jeff



Tue, 07 Oct 2003 21:57:54 GMT  
 unsigned word to signed word in RB

Quote:

> I Have a value between 0-65535 and i need -32767 - (+32767)..I've
> completely forgot how to do especially without bitwise operators... Can
> anyone refresh my memory please?

x=0-65535
y=-32767 - (+32767)

than:

x=y+&H8000

and

y=x-&H8000

PS: &H8000 is 32768

Mfg
Christian

--
Spiel des Lebens 3.0 ist fertig!
Sie werden es nicht wiedererkennen, so viele neue Grafiken sind drin :-)

http://www.christians-software.de (Kostenlose Mac/Win Software)



Tue, 07 Oct 2003 22:49:12 GMT  
 unsigned word to signed word in RB

Quote:

> I Have a value between 0-65535 and i need -32767 - (+32767)..I've
> completely forgot how to do especially without bitwise operators... Can
> anyone refresh my memory please?

I think it is faster to do a subtraction.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Wed, 08 Oct 2003 02:08:55 GMT  
 unsigned word to signed word in RB
dim value as integer
// value is your unsigned number

if BitWiseAnd(value, &h8000) then
value=BitWiseOr(&hffff0000, value)
else
// value should already hold your value
end if



PM:

Quote:
> I Have a value between 0-65535 and i need -32767 - (+32767)..I've
> completely forgot how to do especially without bitwise operators... Can
> anyone refresh my memory please?
> Eli

--

Nick Vellios                 Phone:  408.266.6478
CEO                          Cell:      408.674.5656
Squirrel Software            Fax:      408.265.9859

San Jose, Ca 95118           http://www.*-*-*.com/

PlayBoy Advance:  GameBoy Advance Emulator/De{*filter*} for the Macintosh
Visual MacStandardBasic:  Visual Basic style development environment for the
Macintosh.
JavaGroove:  Visual Java development environment for the Macintosh.

"Life is a test, only a test...If this were REAL life, we would have been
given better instructions."



Wed, 08 Oct 2003 05:38:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adding a signed word to unsigned word...

2. unsigned and partial-word tyes

3. WinAPI.CLW (WinEQU.CLW) Bug on WORD EQUATE (SIGNED)

4. How to replace one or two words with one word with one line of awk code

5. Word 97 and word 2000 - calling from clarion - HELP

6. Word by word cross reference

7. More MF.Fun WORD-RIGHT and WORD-LEFT

8. Class(y) 2.4b, with documentation for MS-Word 97, MS-Word 6.0 and WordPerfect 7.0

9. My final word on word size

10. copy replacing part of words, instead of complete word

11. Taking an array of unsigned word an using it in a subVI that accepts an unsigned long

12. Signed/Unsigned Documentation CW2.002

 

 
Powered by phpBB® Forum Software