How to split a Word into two-8bit Bytes.

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

How to split a Word into two-8bit Bytes.

Post by Francesco.C » Sat Jul 18, 2009 11:35 am

Hi there,

I am stuck on a really simple operation. :?

I have a value X
I need to to split it into two byte for saving into memory locations.

===================

X As Word
Low_byte, High_byte As Byte

X= %1111001101110101 // for example

Low_byte= X AND 255. // It works I get the lower byte of X

High_byte = ??? // I am stuck here

===================================

The AND operation will not work with the high byte because X is 16-bit
while Low_byte is 8-bit. AND operation will check only the lower byte of X.

If I make High_byte into a Word, it will work! But then I will end-up
with a 16-bit value. Not suitable for a memory location.


Any help? Please!


Regards.

Francesco C.

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Post by Francis » Sat Jul 18, 2009 1:14 pm

Have a look at the modifiers
byte0 etc.

Dim MyWord as word
DIm LByte , HByte as Byte
|
|
LByte = MyWord.byte0
HByte = MyWord.byte1

You can do it by declaration alias as well.

Dim MyWord as word
Dim LByte as MyWord.byte0,
HByte as MyWord.byte1

Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

Post by Francesco.C » Sat Jul 18, 2009 2:08 pm

Francis,

Thank you very much, it works! :lol:

Francesco C

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Post by Francis » Sat Jul 18, 2009 2:36 pm

Thats great.

All these modifiers you can do and aliasing are really useful.

Post Reply