fLaXx

Integer to Byte

6 posts in this topic

I am working with integer/word in Gx Works 2, and i am wondering if there is a easy, smart way to split it into two bytes.

Example :

i get two values in data type byte, this is combined into integer in the gateway and im getting both values in the integer. i then need to split them up again. Maybe poorly explained, but i hope its understandable.

Any tips is appreciated!

Share this post


Link to post
Share on other sites

Use "AND" (to mask out the upper byte) and "SHR" (shift-bits right to move the upper byte into a new word):

Lower Byte: AND [data] 16#00FF -> [outData1] (will only pass the lower byte to the output)
Upper Byte: SHR [data] K8 [outData2] (will shift the upper 8 bits 8 positions to the right).

Will this work?

Share this post


Link to post
Share on other sites

Interesting! I will try this when i get back to work.

Thanks!

Share this post


Link to post
Share on other sites

Take a look at the WTOB instruction, it's quite handy but then you need to convert your integer to word format

Share this post


Link to post
Share on other sites

I am having similar problem.

How to send two bytes data into one word.

I want to send first byte into lower word and second byte into upper word.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now