Skip to content

Instantly share code, notes, and snippets.

@vitalyp
Created October 16, 2014 23:17
Show Gist options
  • Save vitalyp/2889f1fa9b4bfed1dbe2 to your computer and use it in GitHub Desktop.
Save vitalyp/2889f1fa9b4bfed1dbe2 to your computer and use it in GitHub Desktop.
How to calculate 32 bit CRC in Ruby on rails
[vitalyp]:~/dev/current/ultimate-proto on develop_prototype_listing*
$ irb
2.1.2 :001 > require 'zlib'
=> true
2.1.2 :002 > crc32 = Zlib::crc32('input field value')
=> 1873826587
2.1.2 :003 > crc32 = Zlib::crc32('input field ')
=> 1511246425
2.1.2 :004 > crc32 = Zlib::crc32('a')
=> 3904355907
2.1.2 :005 > crc32 = Zlib::crc32('a')
=> 3904355907
2.1.2 :006 > crc32 = Zlib::crc32('ab')
=> 2659403885
2.1.2 :007 > crc32 = Zlib::crc32('ba')
=> 749160980
2.1.2 :008 > crc32 = Zlib::crc32('')
=> 0
2.1.2 :009 > crc32 = Zlib::crc32('1')
=> 2212294583
2.1.2 :010 > crc32 = Zlib::crc32('2')
=> 450215437
2.1.2 :011 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment