Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: x.25 Pin
Ghazi H. Wadi7-Jun-01 15:19
Ghazi H. Wadi7-Jun-01 15:19 
GeneralRe: x.25 Pin
trishv8-Jun-01 3:31
trishv8-Jun-01 3:31 
GeneralGood Pin
6-Jun-01 8:17
suss6-Jun-01 8:17 
GeneralAnonymous moron spam Pin
Christian Graus6-Jun-01 12:51
protectorChristian Graus6-Jun-01 12:51 
Generalusing bitwise operators Pin
hearties6-Jun-01 7:58
hearties6-Jun-01 7:58 
GeneralRe: using bitwise operators Pin
Stan Shannon6-Jun-01 8:43
Stan Shannon6-Jun-01 8:43 
Generaloops! Pin
Stan Shannon6-Jun-01 9:08
Stan Shannon6-Jun-01 9:08 
GeneralRe: using bitwise operators Pin
Pavlos Touboulidis6-Jun-01 8:59
Pavlos Touboulidis6-Jun-01 8:59 
First of all, a small correction:
11110101 | 00000100 = 11110101
11110101 & 00000100 = 00000100

What are you trying to do? Do you want to check whether a specific bit is on?

Here's some quick information on bitwise operators:
OR (|) :
0 | 0 = 0,
1 | 0 = 1,
1 | 0 = 1,
1 | 1 = 1

AND (&) :
0 & 0 = 0,
1 & 0 = 0,
0 & 1 = 0,
1 & 1 = 1

XOR (^) :
0 ^ 0 = 0,
1 ^ 0 = 1,
0 ^ 1 = 1,
1 ^ 1 = 0

Now some examples:
value = 0xF4;
// 76543210
// 11110100
To turn on bit 1 : value |= 2; (value = value | 2; 2 because 2^1 = 2)
To turn on but 4 : value |= 16; (because 2^4 = 16)
To turn off bit 2: value &= ~4; (~4 is an int, all bits on except bit 2)

To check whether bit 5 is on:
if (value & 32) // 2^5 = 32, or 0x20
// it's on

Note that value & 32 does not return 1, but 32.
To get a result of 1 or 0 only, you can:
1) Use the and operator to turn off all other bits
2) Use a right shift (>>) to move bit 5 to 0
Example: (value&32) >> 5; (returns 1 or 0)

Hope this answers your question (and I hope I did't make any ridiculous errors
Eek! | :eek: )
GeneralRe: using bitwise operators Pin
hearties6-Jun-01 21:20
hearties6-Jun-01 21:20 
GeneralColoring individual items in List Control using SDK Pin
gb6-Jun-01 7:42
gb6-Jun-01 7:42 
GeneralRe: Coloring individual items in List Control using SDK Pin
Michael Dunn6-Jun-01 9:24
sitebuilderMichael Dunn6-Jun-01 9:24 
GeneralMFC dialog box question Pin
6-Jun-01 7:17
suss6-Jun-01 7:17 
GeneralRe: MFC dialog box question Pin
Igor Sukhov6-Jun-01 7:39
Igor Sukhov6-Jun-01 7:39 
GeneralRe: MFC dialog box question Pin
7-Jun-01 2:20
suss7-Jun-01 2:20 
GeneralMSCOMM QUESTION !!! Pin
Hadi Rezaee6-Jun-01 5:56
Hadi Rezaee6-Jun-01 5:56 
GeneralRe: MSCOMM QUESTION !!! Pin
Carlos Antollini6-Jun-01 6:31
Carlos Antollini6-Jun-01 6:31 
GeneralRe: MSCOMM QUESTION !!! Pin
Hadi Rezaee6-Jun-01 7:16
Hadi Rezaee6-Jun-01 7:16 
GeneralRe: MSCOMM QUESTION !!! Pin
Carlos Antollini6-Jun-01 7:38
Carlos Antollini6-Jun-01 7:38 
GeneralRe: MSCOMM QUESTION !!! Pin
Hadi Rezaee6-Jun-01 16:37
Hadi Rezaee6-Jun-01 16:37 
GeneralRe: MSCOMM QUESTION !!! Pin
Ghazi H. Wadi8-Jun-01 5:16
Ghazi H. Wadi8-Jun-01 5:16 
GeneralRe: MSCOMM QUESTION !!! Pin
D.D. de Kerf6-Jun-01 20:39
D.D. de Kerf6-Jun-01 20:39 
GeneralRe: MSCOMM QUESTION !!! Pin
Hadi Rezaee7-Jun-01 1:21
Hadi Rezaee7-Jun-01 1:21 
GeneralImage Format Pin
A T I F6-Jun-01 4:24
A T I F6-Jun-01 4:24 
GeneralRe: Image Format Pin
6-Jun-01 5:27
suss6-Jun-01 5:27 
GeneralRe: Image Format Pin
Christian Graus6-Jun-01 9:26
protectorChristian Graus6-Jun-01 9:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.