How to do a binary left shift in a integer value using Ruby?
I'm trying to do a left shift binary operation but I'm getting a strange char instead of the move..
I think that it should perform like this: (java)
b = (b >> 2); //0011 1111
b = (b << 2); //1111 1100
I'm doing this in ruby:
currentRed = ChunkyPNG::Color.r(image[x,y])
currentGreen = ChunkyPNG::Color.g(image[x,y])
currentBlue = ChunkyPNG::Color.b(image[x,y])
binRed = currentRed.to_s.unpack("b*")[0]
binGreen = currentGreen.to_s.unpack("b*")[0]
binBlue = currentBlue.to_s.unpack("b*")[0]
puts "original"
puts "r #{binRed}"
puts "g #{binGreen}"
puts "b #{binBlue}"
puts "------"
binRed = binRed << 2
binGreen = binGreen << 2
binBlue = binBlue << 2
puts "new"
puts "r #{binRed}"
puts "g #{binGreen}"
puts "b #{binBlue}"
and getting it:
thank you in advance..