From: Robert Klemme Date: 2005-05-05T01:09:48+09:00 Subject: Re: Fixnum's binary representation camsight@gmail.com wrote: > Hi, people! > > As far as I know, Ruby's Fixnum is 30-bit signed integer. > One bit is used as a flag for whether it's a direct value. > Another bit is used for non-Fixnum direct values. > I wondered how Fixnum#[] works and tested it. > look like. > My guess is that Fixnum#[] works as if it's 32-bit signed integer. > It's not showing its real binary representation. > Is my guess true? Yes. > My another question is that even if (2 ** 31 - 1) is not a Fixnum, the > above code works for it (Actually Bignum#[]). > If the number is bigger than that, [] doesn't work. For which numbers do you have problems? I don't see any so far >> 100.times {|sh| raise unless sh==0||(1 << sh)[0] == 0} => 100 >> (1<<100).class => Bignum > Fixnum#[] and Bignum#[] are cleverly hiding the internal facts and are > made to simulate 32-bit signed integers? Yes. Kind regards robert