Click here to Skip to main content
15,913,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: plzzz Hellppp meeeee exercise for tomorroww Pin
Hamid_RT4-Nov-07 3:07
Hamid_RT4-Nov-07 3:07 
AnswerRe: plzzz Hellppp meeeee exercise for tomorroww Pin
Stephen Hewitt4-Nov-07 3:19
Stephen Hewitt4-Nov-07 3:19 
AnswerRe: plzzz Hellppp meeeee exercise for tomorroww Pin
ThatsAlok4-Nov-07 18:54
ThatsAlok4-Nov-07 18:54 
QuestionSMTP mail server Pin
bigdenny2004-Nov-07 1:04
bigdenny2004-Nov-07 1:04 
Questionwhich way is more efficient to check bit value Pin
George_George4-Nov-07 1:02
George_George4-Nov-07 1:02 
AnswerRe: which way is more efficient to check bit value Pin
David Crow4-Nov-07 2:48
David Crow4-Nov-07 2:48 
GeneralRe: which way is more efficient to check bit value Pin
George_George4-Nov-07 18:15
George_George4-Nov-07 18:15 
AnswerRe: which way is more efficient to check bit value Pin
Chris Losinger4-Nov-07 5:47
professionalChris Losinger4-Nov-07 5:47 
2 will be much faster, for data which is likely to have a lot of 0 bytes.

and, as long as you're checking for 0, you might as well test for 255 (all bit set), too.

and, that brings up a question: is there a way to test all the other bit patterns a byte can have without having to shift and mask each one ?

the answer is Yes.

int look_up_table[256];
look_up_table[0] = -1; // no bits set
look_up_table[1] = 0; // first bit set is bit 0
look_up_table[2] = 1; // first bit set is bit 1
look_up_table[3] = 1; // first bit set is bit 1
look_up_table[4] = 2; // first bit set is bit 2
look_up_table[5] = 2; // first bit set is bit 2
look_up_table[6] = 2; // first bit set is bit 2
look_up_table[7] = 2; // first bit set is bit 2
look_up_table[8] = 3; // first bit set is bit 3
...
look_up_table[255] = 7; // first bit set is bit 7

then, to see which bit is set:

int first_bit_set = look_up_table[byte_to_test];

that will outperform any shift-and-mask algorithm probably by an order f magnitude.


GeneralRe: which way is more efficient to check bit value Pin
George_George4-Nov-07 18:26
George_George4-Nov-07 18:26 
GeneralRe: which way is more efficient to check bit value Pin
Chris Losinger5-Nov-07 0:58
professionalChris Losinger5-Nov-07 0:58 
GeneralRe: which way is more efficient to check bit value Pin
George_George5-Nov-07 1:13
George_George5-Nov-07 1:13 
GeneralRe: which way is more efficient to check bit value Pin
David Crow5-Nov-07 3:43
David Crow5-Nov-07 3:43 
GeneralRe: which way is more efficient to check bit value Pin
George_George5-Nov-07 18:41
George_George5-Nov-07 18:41 
QuestionCreate a file, containing folder contents Pin
TheRamon3-Nov-07 23:38
TheRamon3-Nov-07 23:38 
AnswerRe: Create a file, containing folder contents Pin
Nelek4-Nov-07 21:51
protectorNelek4-Nov-07 21:51 
Questionlocal system account Pin
ginjikun3-Nov-07 22:59
ginjikun3-Nov-07 22:59 
QuestionNetwork Monitor Pin
AhmedOsamaMoh3-Nov-07 21:46
AhmedOsamaMoh3-Nov-07 21:46 
QuestionExport string from Dll Pin
Max++3-Nov-07 21:02
Max++3-Nov-07 21:02 
QuestionTracking a mouse movement inside a dialog without Tab controls Pin
Larry Mills Sr3-Nov-07 15:39
Larry Mills Sr3-Nov-07 15:39 
AnswerRe: Tracking a mouse movement inside a dialog without Tab controls Pin
Nelek4-Nov-07 21:41
protectorNelek4-Nov-07 21:41 
GeneralRe: Tracking a mouse movement inside a dialog without Tab controls Pin
Larry Mills Sr5-Nov-07 5:57
Larry Mills Sr5-Nov-07 5:57 
GeneralRe: Tracking a mouse movement inside a dialog without Tab controls [modified] Pin
Nelek5-Nov-07 20:30
protectorNelek5-Nov-07 20:30 
AnswerRe: Tracking a mouse movement inside a dialog without Tab controls Pin
Mark Salsbery5-Nov-07 5:54
Mark Salsbery5-Nov-07 5:54 
GeneralRe: Tracking a mouse movement inside a dialog without Tab controls Pin
Larry Mills Sr5-Nov-07 6:03
Larry Mills Sr5-Nov-07 6:03 
GeneralRe: Tracking a mouse movement inside a dialog without Tab controls Pin
Mark Salsbery5-Nov-07 6:34
Mark Salsbery5-Nov-07 6:34 

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.