From: William Djaja Tjokroaminata Date: 2002-10-16T14:02:23+09:00 Subject: Re: Porting a CRC function to ruby Hi Matthew, The problem is not signed vs unsigned. The problem is, given an int, the Ruby Fixnum is obtained by left shifting the int by one (and setting the least significant bit to 1). Therefore, before you do your CRC, you have to right shift the Fixnum. (Just be careful that the right shifted version of the Fixnum may not be a valid Ruby object, so "don't interact with Ruby" using the right shifted version.) The problem is probably more complicated if the data type used in the C function is unsigned int or unsigned long. In this case probably you have to use Bignum (and know how Bignum is implemented internally in Ruby). However, as Ruby performs conversion between Bignum and Fixnum automatically, you have to be careful too. Finally, because when you are dealing with communication packets the Ruby Fixnum is not really "clean", probably it is better and easier to use Ruby BitVector instead of Fixnum. Regards, Bill =========================================================================== Matthew Miller wrote: > Hello, > I'm a bit new to Ruby and I'm having trouble porting a CRC function from C++ > to Ruby. The problem seems to be that Fixnums are signed while the data type > used in the C function is an unsigned short. I guess I could compile the C++ > function into a shared object and load that in Ruby, but I would like to > avoid that if possible as it is currently over my head.