Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGEVGE suggests, but extended to a whole byte).

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).

Add x-ref URL
Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).

Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

This works if you initialize the table correctly.

static const unsigned char one_bits_in_byte[] = { 0, 1, 1, 2, 1, ... }; int counter = one_bits_in_byte[myValue & 0xFF]; 

Of course, you'd write a program with a loop in it to generate the table so that your final program doesn't have a loop in it. If you are feeling cost conscious, you can encode just the data for 0..15 and process the two halves (nybbles) of the value with shifts. But with 24 GB of physical memory, this is unlikely to be a major problem. And you could also simply compute the value on demand with masking operations, etc (like VGE suggests, but extended to a whole byte).