Click here to Skip to main content
15,902,908 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: FRACTAL FORMULAS Pin
cyndy_northrup5-Sep-07 15:10
cyndy_northrup5-Sep-07 15:10 
GeneralRe: FRACTAL FORMULAS Pin
Russell'5-Sep-07 22:09
Russell'5-Sep-07 22:09 
AnswerRe: FRACTAL FORMULAS Pin
Luc Pattyn4-Sep-07 23:06
sitebuilderLuc Pattyn4-Sep-07 23:06 
Questioncontiguous bits algorithm. Pin
chandu0042-Sep-07 22:09
chandu0042-Sep-07 22:09 
AnswerRe: contiguous bits algorithm. Pin
Russell'2-Sep-07 22:44
Russell'2-Sep-07 22:44 
AnswerRe: contiguous bits algorithm. Pin
cp98762-Sep-07 22:48
cp98762-Sep-07 22:48 
GeneralRe: contiguous bits algorithm. Pin
chandu0042-Sep-07 23:14
chandu0042-Sep-07 23:14 
GeneralRe: contiguous bits algorithm. [modified] Pin
cp98763-Sep-07 0:04
cp98763-Sep-07 0:04 
You should be able to extend this - do something like:


const int hi1 = {0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0};

int GetWordStatus(int word, int wordlength)
   {
   ASSERT(wordLength <= 8  &&  wordLength >= 0);
   int x = word & ~hi1[wordLength]; // may not be necessary depending on what data can be sent
   switch (x)
      {
      case 0x01:
      case 0x03:
      case 0x07:
      case 0x0F:
      case 0x1F:
      case 0x3F:
      case 0x7F:
         return 1;
      }
   x = word | hi1[wordLength];
   switch (x)
      {
      case 0x80:
      case 0xC0:
      case 0xE0:
      case 0xF0:
      case 0xF8:
      case 0xFC:
      case 0xFE:
         return 2;
      }
   return 0;
   }


It may be a bit inefficient for small wordlengths, if it is a problem you should spend some time and make it better.




-- modified at 6:57 Monday 3rd September, 2007

The reason I am suggesting a switch statement rather than a loop is that I thought the reason that in C/C++ the case values had to be constants was so that the compiler could order them and implement the switch as a simple binary search, so for N case statements there would be only log2(N) comparisons. I can't easily find a reference for this now - does anyone know if this happens?



Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

GeneralRe: contiguous bits algorithm. Pin
Russell'3-Sep-07 1:09
Russell'3-Sep-07 1:09 
GeneralRe: contiguous bits algorithm. Pin
Russell'3-Sep-07 0:26
Russell'3-Sep-07 0:26 
AnswerRe: contiguous bits algorithm. Pin
rihdus3-Sep-07 2:06
rihdus3-Sep-07 2:06 
AnswerRe: contiguous bits algorithm. Pin
Luc Pattyn3-Sep-07 5:37
sitebuilderLuc Pattyn3-Sep-07 5:37 
GeneralRe: contiguous bits algorithm. Pin
Russell'3-Sep-07 5:46
Russell'3-Sep-07 5:46 
GeneralRe: contiguous bits algorithm. Pin
cp98763-Sep-07 19:55
cp98763-Sep-07 19:55 
AnswerRe: contiguous bits algorithm. Pin
polyhedron4-Sep-07 16:47
polyhedron4-Sep-07 16:47 
AnswerRe: contiguous bits algorithm. Pin
Nelek12-Sep-07 5:05
protectorNelek12-Sep-07 5:05 
Questionwhich one would be faster? Pin
Mushtaque Nizamani2-Sep-07 21:30
Mushtaque Nizamani2-Sep-07 21:30 
AnswerRe: which one would be faster? Pin
Michael Dunn2-Sep-07 21:40
sitebuilderMichael Dunn2-Sep-07 21:40 
Answer Re: which one would be faster? Pin
Russell'2-Sep-07 22:03
Russell'2-Sep-07 22:03 
JokeRe: which one would be faster? Pin
Russell'2-Sep-07 22:05
Russell'2-Sep-07 22:05 
AnswerRe: which one would be faster? Pin
rihdus2-Sep-07 22:21
rihdus2-Sep-07 22:21 
GeneralRe: which one would be faster? Pin
Russell'2-Sep-07 22:36
Russell'2-Sep-07 22:36 
GeneralRe: which one would be faster? Pin
Luc Pattyn3-Sep-07 5:43
sitebuilderLuc Pattyn3-Sep-07 5:43 
GeneralRe: which one would be faster? Pin
Mushtaque Nizamani2-Sep-07 22:51
Mushtaque Nizamani2-Sep-07 22:51 
GeneralRe: which one would be faster? Pin
chandu0042-Sep-07 23:17
chandu0042-Sep-07 23:17 

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.