From: jzakiya@... (Jabari Zakiya) Date: 2002-04-10T10:31:47+09:00 Subject: Rotate, et al I have a newbie question about rotate operators. I want to do 32-bit left/right rotates. I can do something like the following: List 1. def rol(n, s) n &= 0xffffffff n = (n<>32-s)&0xffffffff end which does what I want, even for values > 32-bits. Thus, given some 32-bit hex value: a = 0x12345678 I can do: rol(a, s) or rol a, s where s = 0..32 But what I really want to do is: a.rol(s). 1) Is this the best way to want to do this? 2) What is the fastest way to do 32-bit rotates in Ruby? I also want to do this with the arithmetic operations '+', '-', '*', and '/', where everything is for 32 bits. I know this must seem trivial, but hey, help me out here. :-) Also, a = 0x40000000 -- a.type -> BIGNUM b = 0x20000000 -- b.type -> FIXNUM A number up to 30-bits long is type FIXNUM, while any number > 30-bits is type BIGNUM. Why dat? On a 32-bit machine a = 0x80000000 will fit in a single register and memory location. 3) What's was the philosphy for removing the machine architecture from the consideration of number types? 4) What is the easiest way to check for 'endianess' of a machine in Ruby? Also, coming from Forth, where I have virtually complete access and control over the machine, I was wondering if there are any libraries or extensions in Ruby (not C, etc) that allow you to write essentially assmebly code to make things faster. Since Pentium (PC) class CPUs have single cycle rotate, et al, instructions, it would be nice to somehow access them, or at least have classes/methods compile directly to them. Jabari Zakiya