Method: Integer#lsb_bit_position

Defined in:
lib/setfu.rb

#lsb_bit_positionObject



1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/setfu.rb', line 1247

def lsb_bit_position
  return nil if zero?
  pos = 0
  n = self
  while (n & 0xffffffffffffffff) == 0
    n >>= 64
    pos += 64
  end
  while (n & 0xff) == 0
    n >>= 8
    pos += 8
  end
  mask = 1
  loop do
    break if mask == (n & mask)
    mask <<= 1
    pos += 1
  end
  return pos
end