From: Robert Klemme Date: 2005-05-05T02:09:57+09:00 Subject: Re: Fixnum's binary representation schrieb im Newsbeitrag news:1115223668.955656.66750@o13g2000cwo.googlegroups.com... > Thanks, Robert! > >> For which numbers do you have problems? I don't see any so far > > I mean... > If Bignum#[] is made to simulate 32-bit signed integers, it can't show > numbers with more than 32-bit representation. > Well, positive numbers will be okay. > But what about negative numbers? > When can I expect the sign bit? Well, since Bignums can be arbitrary size, you have to decide. The values returned by Fixnum#[] and Bignum#[] represent bits of a two complement's arbitrary size binary number. If you view it from this perspective, you'll see that there is no single sign bit. Negative numbers have *all* the higher bits set to 1. > I assume that numbers beyond 32-bit are not suitable for Bignum#[]. > Do you agree? Not at all. >> n = -(1<<100) => -1267650600228229401496703205376 >> 200.times{|i| print i, " ", n[i], "\n"} 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 .... 95 0 96 0 97 0 98 0 99 0 100 1 101 1 102 1 103 1 104 1 .... 195 1 196 1 197 1 198 1 199 1 => 200 As you clearly see, the representation is ok. Btw, you'll notice the same effect with Fixnum#[] - because these methods do not represent the actual binary representation in mem but try to represent the general concept of signed binary numbers: >> (-1)[100] => 1 >> (-1)[1<<100] => 1 Kind regards robert