Page 1 of 1
format to change bit by byte operation in HITEC compiler.?

Posted:
Fri Aug 23, 2013 9:26 am
by aswad
hello, can i know how the format that we can change bit by bit from byte.
let say,,
a=0b00000000
in decision making
if ( button1=1)
{bit 0 of a=1;}
if ( button2=1)
{bit 1 of a=1;}
if ( button3=1)
{bit 3 of a=1;}
anyone can help?
Re: format to change bit by byte operation in HITEC compiler

Posted:
Fri Aug 23, 2013 4:47 pm
by A380
One of the methods is you have to declare 'a' as a struct as following.
struct
{
unsigned char Button1 :1;
unsigned char Button2 :1;
unsigned char Button3 :1;
unsigned char B4 :1;
unsigned char B5 :1;
unsigned char B6 :1;
unsigned char B7 :1;
unsigned char B8 :1;
}a;
if(button1 == 1){ a.Button1 = 1; }
if(button2 == 1){ a.Button2 = 1; }
if(button3 == 1){ a.Button3 = 1; }
Re: format to change bit by byte operation in HITEC compiler

Posted:
Fri Aug 23, 2013 8:57 pm
by shahrul
Can use operation AND and OR.
If want set bit 0, a=a|0x01
any bit OR with 1 will result 1
If want clear bit 0, a=a&0xFE
any bit AND with 0 will result 0
Re: format to change bit by byte operation in HITEC compiler

Posted:
Sat Aug 24, 2013 12:22 am
by aswad
yes, i done with bitwise operation.