234 views
in Embedded Wizard Studio by

How would I do the following in Chora?

uint8 x;

 x  &=  ~(1 << 0);

x = x & ~(1 << 0); doesn't seem to work either.

1 Answer

0 votes
by

Hello Mike,

thank you very much for this report. You have encountered an error in Chora compiler. The ~ operator seems to accept 32-bit signed/unsigned operands only. The constant number 1, however, is considered as int8 value. The Chora compiler reports thereupon an error message. We will fix the error in the next version.

Trying to cast the value explicitly to int32 does not work because of optimization the constant value is re-evaluated resulting again in int8. Following are the few possible workarounds to achieve your desired results:

Option 1:

var uint8 x    = ...;
var int32 val1 = 1;

x = uint8( x & ~( val1 << 0 ));

Option 2:

var uint8 x = ...;

x = uint8( x & (( 1 << 0 ) ^ 0xFFFFFFFF ));

I hope the workarounds help you further.

Best regards

Paul Banach

by
Forgot to ask, how do I do the following:

x |= (1<<1);

By doing...?

  x = uint8(x | ( 1 << 1 ));
by

Hello Mike,

if you are using Embedded Wizard < 10.00 following should work:

var uint8 x = ...;

x = uint8( x | ( 1 << 1 ));

With Embedded Wizard >= 10.00 you can implement the operation by using the compound assignment operators. The explicit typecast can be omitted in this case:

var uint8 x = ...;

x |= 1 << 1;

Does it help you?

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...