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
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
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/

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

 Page 1 of 1 [ 5 post ]

Relevant Pages