Ruby Bitwise Notes

Posted: 03/29/2009

Start with an integer:

  x = 1

Shift by two bit positions:

  x <<= 2

OR with 1:

  x |= 1

AND with 14 (hex E):

  x &= 0xE
  # is the same as:
  x &= 14

Get binary representation:

  x.to_s(2)

Get hex representation:

  x.to_s(16)

XOR (exclusive OR) with 1

  x ^= 1

About Me

I'm a skier, web developer, entrepreneur, freelancer, and all around stand-up guy living in Manhattan. This is me, repping one of my favorite shirts...

Follow me on twitter or send me an email.

All Posts

Music Blogs