Click here to Skip to main content
15,905,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralParse a binary number Pin
NewHSKid22-Sep-03 7:51
NewHSKid22-Sep-03 7:51 
GeneralRe: Parse a binary number Pin
David Crow22-Sep-03 8:11
David Crow22-Sep-03 8:11 
GeneralRe: Parse a binary number Pin
NewHSKid22-Sep-03 8:36
NewHSKid22-Sep-03 8:36 
GeneralRe: Parse a binary number Pin
David Crow22-Sep-03 8:41
David Crow22-Sep-03 8:41 
GeneralRe: Parse a binary number Pin
NewHSKid22-Sep-03 8:50
NewHSKid22-Sep-03 8:50 
GeneralRe: Parse a binary number Pin
David Crow22-Sep-03 8:54
David Crow22-Sep-03 8:54 
GeneralRe: Parse a binary number Pin
NewHSKid23-Sep-03 8:23
NewHSKid23-Sep-03 8:23 
GeneralRe: Parse a binary number Pin
David Crow23-Sep-03 8:45
David Crow23-Sep-03 8:45 
AND means that BOTH bits must be 1 in order for the resulting bit to be 1.

10100000000100101011010000110101
AND                         1111
================================
                             101

Continuing to bit-shift the value to the right one word at a time means that you can use 0x0000000f exclusively.

You could also have had something like:

DWORD dw = 0xA012B435;<br />
WORD w1 = dw & 0x0000000f;<br />
WORD w2 = (dw & 0x000000f0) >> 8;<br />
WORD w3 = (dw & 0x00000f00) >> 16;<br />
WORD w4 = (dw & 000000f000) >> 24;

or
WORD w4 = dw & 000000f000;<br />
w4 >>= 24;


Whether you bit-shift before or after the AND operation is not important, but doing so beforehand does lend itself to more readable code.


Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?

GeneralRe: Parse a binary number Pin
ASchunk22-Sep-03 8:21
ASchunk22-Sep-03 8:21 
GeneralGroupbox question Pin
ns22-Sep-03 7:48
ns22-Sep-03 7:48 
GeneralRe: Groupbox question Pin
David Crow22-Sep-03 8:15
David Crow22-Sep-03 8:15 
GeneralRe: Groupbox question Pin
ns22-Sep-03 9:12
ns22-Sep-03 9:12 
GeneralStruct Alignment Pin
Mike Doner22-Sep-03 6:38
Mike Doner22-Sep-03 6:38 
GeneralRe: Struct Alignment Pin
David Crow22-Sep-03 7:21
David Crow22-Sep-03 7:21 
GeneralRe: Struct Alignment Pin
Mike Doner22-Sep-03 7:38
Mike Doner22-Sep-03 7:38 
GeneralRe: Struct Alignment Pin
David Crow22-Sep-03 7:59
David Crow22-Sep-03 7:59 
GeneralRe: Struct Alignment Pin
Mike Doner22-Sep-03 8:27
Mike Doner22-Sep-03 8:27 
GeneralRe: Struct Alignment Pin
David Crow22-Sep-03 9:05
David Crow22-Sep-03 9:05 
Generalpackaging stuff Pin
act_x22-Sep-03 6:17
act_x22-Sep-03 6:17 
GeneralCDialogBar Pin
DeckY22-Sep-03 4:33
DeckY22-Sep-03 4:33 
GeneralRe: CDialogBar Pin
JWood22-Sep-03 9:54
JWood22-Sep-03 9:54 
GeneralPrinting RTF text with transparent BK Pin
CodeBrain22-Sep-03 4:31
CodeBrain22-Sep-03 4:31 
GeneralCSlider Pin
DeckY22-Sep-03 4:24
DeckY22-Sep-03 4:24 
GeneralRe: CSlider Pin
David Crow22-Sep-03 7:22
David Crow22-Sep-03 7:22 
GeneralRe: CSlider Pin
Anonymous22-Sep-03 20:40
Anonymous22-Sep-03 20:40 

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.