|
-
Feb 25th, 2015, 05:10 PM
#1
Thread Starter
Junior Member
Math Issue - Long to WORD converstion problem
I need to take a long value, which ranges between 0~32768, and convert it into a WORD.
I've dimmed two BYTE data types:
Dim Hbyte As Byte
Dim Lbyte As Byte
What is the easiest way to convert the long value into these two bytes? The most painful way is:
TempLONG holds a value ranging between 0 ~ 32768
If TempLONG > 32767 Then TempLONG = TempLONG - 32768: Hbyte = Hbyte + 128
If TempLONG > 16383 Then TempLONG = TempLONG - 16384: Hbyte = Hbyte + 64
If TempLONG > 8191 Then TempLONG = TempLONG - 8192: Hbyte = Hbyte + 32
If TempLONG > 4095 Then TempLONG = TempLONG - 4096: Hbyte = Hbyte + 16
If TempLONG > 2047 Then TempLONG = TempLONG - 2048: Hbyte = Hbyte + 8
If TempLONG > 1023 Then TempLONG = TempLONG - 1024: Hbyte = Hbyte + 4
If TempLONG > 511 Then TempLONG = TempLONG - 512: Hbyte = Hbyte + 2
If TempLONG > 255 Then TempLONG = TempLONG - 256: Hbyte = Hbyte + 1
LByte = TempLONG
The above routine works, but come on... 
Any ideas?
0x34
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|