Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created May 26, 2016 21:24
Show Gist options
  • Save jrelo/6b9f2c01e787d7199834beb2a9f464ad to your computer and use it in GitHub Desktop.
Save jrelo/6b9f2c01e787d7199834beb2a9f464ad to your computer and use it in GitHub Desktop.
flip single bit using perl.
[16:25:27] root@na:~ # echo "A"|xxd -b
0000000: 01000001 00001010 A.
[16:25:30] root@na:~ # echo "A"|perl -e '$byte=shift(@ARGV);$bit=shift(@ARGV);undef $/; $in=<>; substr($in,$byte,1) = substr($in,$byte,1) ^ chr(1<<$bit); print $in' 0 1|xxd -b
0000000: 01000011 00001010 C.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment