in the C compiler get this code working but how to do it in flowcode, any idae pls..
unsigned int32 code;
for(i = 0; i < 32; i++)
if( count > 20)
bit_set(code, (31 - i));
else
bit_clear(code, (31 - i));
how to set or clear individual bits in a veriable??
-
- Valued Contributor
- Posts: 1191
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: how to set or clear individual bits in a veriable??
One way to do it is with '|' (or operator) or to clear bits '&' (and operator)
will set bit 4
will clear bit 4
To set a 'variable' bit
To set or clear multiple bits you can use a mask
will set bits 7..4
Martin
Code: Select all
x = x | (1 << 4)
Code: Select all
x = x & ~(1 << 4)
To set a 'variable' bit
Code: Select all
x = x | (1 << n)
Code: Select all
x = x | 0b11110000
Martin
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
- Contact:
Re: how to set or clear individual bits in a veriable??
Hello! Martin
Wonderful explanation, thank you.
Abhi
Wonderful explanation, thank you.
Abhi