Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/14/06 15:37
Modified:
  12/14/06 15:56

Read: times


 
#129479 - table lookup
Responding to: ???'s previous message
Christoph,

A table lookup would be possible, but a rather complex one.

Let's take your 4-bit example - that would be the table - and let's generate the 8-bit output. I add the number of ones and the number of numbers on that row to each row.
Row4 1 1111b,
Row3 4 0111b, 1011b, 1101b, 1110b,
Row2 6 0011b, 0101b, 0110b, 1001b, 1010b, 1100b,
Row1 4 0001b, 0010b, 0100b, 1000b,
Row0 1 0000b

Now a pseudocode:
for bits = 8 downto 0
  for i = 8 downto 0    
    if i>4 or (bits-i)>4 then shortcut to next bits *
      for j = 1 to length[row[i]]
        for k = 1 to length[row[bits-i]]
          output concatenation of row[i][j] and row[bits-i][k]
        next k
      next j
  next i
next bits

should generate the 8-bit output. IMHO it's quite easy to expand the same for more bits.

Have fun!

JW

-----
* OK I was lazy and some nicer optimisation could come here...
[added later]a good start for optimisation would be to use for i = 4 rather than 8... me stupido :-) [/added later]

List of 40 messages in thread
TopicAuthorDate
Looking for an algorithm.            01/01/70 00:00      
   I'd split it in two (or 4)            01/01/70 00:00      
      I've shown, in increseing detail, how to do it            01/01/70 00:00      
   Sorted, or only counted?            01/01/70 00:00      
      Counting is enough            01/01/70 00:00      
         Not sorting or counting then??            01/01/70 00:00      
            My approach.            01/01/70 00:00      
               Erik's idea is fast and simple!            01/01/70 00:00      
   did you even consider what I posted            01/01/70 00:00      
      I considered lookup tables.            01/01/70 00:00      
         look at my code it is right there            01/01/70 00:00      
         Can you explain your table?            01/01/70 00:00      
            Interpret it in binary            01/01/70 00:00      
               Hhm...            01/01/70 00:00      
                  Use of the table/algorithm            01/01/70 00:00      
                  misunderstanding            01/01/70 00:00      
                     Ah. I thought so.            01/01/70 00:00      
            explanation of table            01/01/70 00:00      
   table lookup            01/01/70 00:00      
   now, I'm confused            01/01/70 00:00      
      The keyword is "enumerate".            01/01/70 00:00      
         i give up since nobody can answer in english            01/01/70 00:00      
            Meaning #1            01/01/70 00:00      
               there must be some language problem here            01/01/70 00:00      
                  Basically, a)            01/01/70 00:00      
                     then this will work (and I believe the fastest)            01/01/70 00:00      
                        maybe yes            01/01/70 00:00      
                           maybe faster, but not6 what he ned            01/01/70 00:00      
                              it's sometimes not easy to describe what one needs            01/01/70 00:00      
                                 Sorting or counting            01/01/70 00:00      
                                    Bit shifting            01/01/70 00:00      
                                    I elaborated.            01/01/70 00:00      
                                       Christoph, have you tried...            01/01/70 00:00      
                                          It looks interesting ..            01/01/70 00:00      
                                             well, you said that...            01/01/70 00:00      
                                                here you are            01/01/70 00:00      
                                                   Works.            01/01/70 00:00      
                                                      compiler            01/01/70 00:00      
                                                         Benchmark            01/01/70 00:00      
                                                            thanks!            01/01/70 00:00      

Back to Subject List