Code Monkey home page Code Monkey logo

bitarray's Issues

issue line 170 in bit_array.c

Hi,

It seems that there is an issue in the function

static word_t __inline windows_popcount(word_t w)
{
  w = w - ((w >> 1) & (word_t)~(word_t)0/3);
  w = (w & (word_t)~(word_t)0/15_3) + ((w >> 2) & (word_t)~(word_t)0/15_3);
  w = (w + (w >> 4)) & (word_t)~(word_t)0/255*15;
  c = (word_t)(w \* ((word_t)~(word_t)0/255)) >> (sizeof(word_t) - 1) \* 8;
}

line 170 in bit_array.c

Best Regards,
Long Yuan

Fails on big-endian processor (microblaze)

If I add 8 bytes to a bit array:
55 31 5A 12 02 31 C3 1E
And then print the bit array's words[0] with printf( "%016" PRIx64"", val ):
1ec33102125a3155
And then I loop through the bits with:
for ( int idx = 0; idx < 64; idx++ )
{
if ( bit_array_get_bit( ba, idx ) == 0 )
printf( "0" );
else
printf( "1" );
}
then I get (I added spaces to make it easier to see):
10101010 10001100 01011010 01001000 01000000 10001100 11000011 01111000
Which is wrong for a big-endian processor. It should be:
01010101 00110001 01011010 00010010 00000010 00110001 11000011 00011110
You can see that the order of the bits within each byte is backwards. You're assuming little-endian ordering.

Tag a new release

Any chance you can tag a new release? Been 57 commits since 2013.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.