How can I convert a 16-bit number into 2 8-bit numbers 
Author Message
 How can I convert a 16-bit number into 2 8-bit numbers

How can I split an integer into 2 addresses (high and low bytes)

I have the code of how to do it in C, but I'm having trouble converting it
to VB :

(Base is an int)

    WBlock[0] = ( Base >> 8 ) & 0xFF ;
    WBlock[1] = Base & 0xFF ;

Could you possibly mail me due to problems with reading news.

Thanks in advance

Rich



Mon, 26 Apr 1999 03:00:00 GMT  
 How can I convert a 16-bit number into 2 8-bit numbers

Quote:

> How can I split an integer into 2 addresses (high and low bytes)
> (Base is an int)

>     WBlock[0] = ( Base >> 8 ) & 0xFF ;
>     WBlock[1] = Base & 0xFF ;
> Thanks in advance

> Rich


Here's two functions that should do the trick.

FUNCTION HByte% (word%)
IF word% >= 0 THEN
                HByte% = word% \ 256
        ELSE
                HByte% = (65536 + word%) \ 256
        END IF
END FUNCTION

FUNCTION LByte% (word%)
IF word% >= 0 THEN
                LByte% = word% MOD 256
        ELSE
                LByte% = (65536 + word%) MOD 256
        END IF
END FUNCTION

Of course, if you know that you'll only be dealing with positive integers
less than 32767 (like a positive signed int in C) just use MOD or '\'
(integer divide). So in order to get the lowbyte value of 23456 just say

PRINT lbyte(23456)

or

PRINT 23456 MOD 256



Mon, 26 Apr 1999 03:00:00 GMT  
 How can I convert a 16-bit number into 2 8-bit numbers


Quote:

>How can I split an integer into 2 addresses (high and low bytes)

>I have the code of how to do it in C, but I'm having trouble convertin
>g it
>to VB :

>(Base is an int)

>    WBlock[0] = ( Base >> 8 ) & 0xFF ;
>    WBlock[1] = Base & 0xFF ;

>Could you possibly mail me due to problems with reading news.

>Thanks in advance

>Rich


Word = 1234     '(0-65535)

Byte0 = Word AND &HFF
Byte1 = (Word AND &HFF00) \ &H100

...or

Byte0 = ASC(MID$(MKI$(Word), 1, 1))
Byte1 = ASC(MID$(MKI$(Word), 2, 1))

Beau Schwabe



Tue, 27 Apr 1999 03:00:00 GMT  
 How can I convert a 16-bit number into 2 8-bit numbers

Quote:

>How can I split an integer into 2 addresses (high and low bytes)

Hi RH!

Lotsa different technques I see! here;s my two cents on how I do it:

Number = 32767
MSB = Number \ 256      'backslash = integer div
LSB = Number MOD 256

Works for me! Ep

Ed Parry - Southern California, USA



Tue, 27 Apr 1999 03:00:00 GMT  
 How can I convert a 16-bit number into 2 8-bit numbers

: How can I split an integer into 2 addresses (high and low bytes)
:
: I have the code of how to do it in C, but I'm having trouble converting it
: to VB :
:
: (Base is an int)
:
:     WBlock[0] = ( Base >> 8 ) & 0xFF ;
:     WBlock[1] = Base & 0xFF ;
:
: Could you possibly mail me due to problems with reading news.
:
: Thanks in advance
:
: Rich

:



Tue, 27 Apr 1999 03:00:00 GMT  
 How can I convert a 16-bit number into 2 8-bit numbers

RI>I have the code of how to do it in C, but I'm having trouble converting it
RI>to VB :

I don't know VB but:

low = Value AND 255
high = (value AND -256)/256



Wed, 28 Apr 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Desperate for help Converting 16 bit app to 32 bit

2. Convert 16-bit vbp to 32-bit?

3. Converting 16 bit to 32 bit

4. Convert 32-BIT MDB Database to 16-bit database

5. Problems converting from 16 bit to 32 bit

6. Converting Reports from 16-bit to 32-bit??

7. converting 16-bit VB4/Access2 to 32-bit

8. Converting a VB4.0 16 Bit app to VB5 32 bit

9. URGENT! Convert 32-bit to 16-bit

10. Converting 16 bit to 32 bit VB 4.0 Pro

11. Convert 16 bit bmp to 24 bit bmp

 

 
Powered by phpBB® Forum Software