title: Ruby binary left shift
body: <p>How to do a binary left shift in a integer value using Ruby?</p>
  
  <hr>
  
  <p>I'm trying to do a left shift binary operation but I'm getting a strange char
  instead of the move..</p>
  
  <p>I think that it should perform like this: (java)</p>
  
  <p>b = (b >> 2); //0011 1111<br>
  b = (b &lt;&lt; 2); //1111 1100 </p>
  
  <p>I'm doing this in ruby:</p>
  
  <pre><code>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 &lt;&lt; 2
  
  binGreen = binGreen &lt;&lt; 2
  binBlue = binBlue &lt;&lt; 2
  
  
  puts "new"
  
  puts "r #{binRed}"
  puts "g #{binGreen}"
  puts "b #{binBlue}"
  </code></pre>
  
  <p>and getting it:</p>
  
  <p><img src="https://i.stack.imgur.com/6Vjrj.png" alt="enter image description here"></p>
  
  <p>thank you in advance..</p>