605 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 - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...