Jump to content

Recommended Posts

Posted

I am attempting to write a function block that will take an input word and convert it into an array of Boolian values to access each bit in the word. Following are details:

 

In/Out Variables: Name:InputWord, In/Out: Input, Data Type: Word

Name:OutputBits, In/Out: In/Out, Data Type: ARRAY[0..15] OF BOOL

Internal Variables: Name: I, Data Type: Int

 

FOR i := 0 TO 15 DO

OutputBits := (InputWord AND (1 SHL i)) <> 0;

END_FOR;

 

I get a “)” is missing error. What am I doing wrong and how can I fix it?


Posted (edited)

SHL needs opening and closing brackets immediately after it.

If I may suggest a much easier way to do this - make a union to break a WORD into a BOOL[16] and then simply write the WORD value to the Union.WORD.

Alternatively you can assign the same address to the WORD as the BOOL array has and the bits will reflect the WORD.

Capture.JPG

Capture3.JPG

Capture2.JPG

Edited by photovoltaic
  • Like 1

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
×
×
  • Create New...