Click here to Skip to main content
11,802,076 members (51,179 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ C# MFC
hello, i saw a demo code which change the function of trigger output from byte by byte to bit by bit, by using both of this symbol,
|= and &=
i wonder what is the function of it.. cause i cant find any solution from google~
Posted 26-Sep-12 20:53pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


to set a bit x, use this functionality:
number |= 1 << x;
to clear a bit x, use this code:
number &= ~(1 << x);
to toggle a bit x, use this code:
number ^= 1 << x;
See here for an explanation:[^]
arnoldxx at 27-Sep-12 3:02am
thanks.. simple and nice explanation~ :)
arnoldxx at 27-Sep-12 3:20am
sorry i m a bit confuse with this code

if(((CStatic*)pWnd)->GetBitmap() != m_bmp_Output_ON)
wResult_4th_8Bits |= 0x80;
VTIO_OutpByte(wSelected_dwBaseAddr+0xcc, (unsigned char)wResult_4th_8Bits);
wResult_4th_8Bits &= 0x7f;
VTIO_OutpByte(wSelected_dwBaseAddr+0xcc, (unsigned char)wResult_4th_8Bits);

can u please explain it to me? thanks
JF2015 at 27-Sep-12 3:34am
The line wResult_4th_8Bits |= 0x80; basically only sets the 8th bit and the line wResult_4th_8Bits &= 0x7f; resets any bit above the 7th bit and leaves the lowest 7 bit unchanged, maybe just to convert a 32bit/16bit/8bit value to 7bit. Why this code performs this action, I can't tell you - this is not clear out of the context.
arnoldxx at 27-Sep-12 3:38am
haha.. its okey, ^^ thanks for the explanation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 485
1 KrunalRohit 341
2 F-ES Sitecore 255
3 Afzaal Ahmad Zeeshan 220
4 CPallini 205
0 OriginalGriff 2,715
1 Maciej Los 1,900
2 KrunalRohit 1,797
3 CPallini 1,550
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100