From: Harry Kakueki Date: 2011-10-22T23:46:55+09:00 Subject: Re: power of 2 code > Rewrite this last program so that the computer asks for the maximum > number and the program computes the corresponding power of two. > > Enter maximum value: > 124123 > 2^17 =131072 is the highest power of 2 less than 124123 > Loops can be confusing sometimes. This won't help you with the loops because it doesn't have loops. But, maybe it can still be helpful. Or, not. :) If the puts statement is confusing, then do it your way. (number-1).to_s(2).size-1 is the exponent. ######### puts "Enter a maximum value: " number = gets.chomp.to_i puts "2^#{(number-1).to_s(2).size-1}" if number >= 1 Harry