use strict; use warnings; my $val = 0; p('Zero'); $val |= 1; p('Or-ed 1'); $val <<= 1; p('shift 1'); $val |= 0; p('Or-ed 0'); $val <<= 1; p('shift 1'); $val |= 1; p('Or-ed 1'); $val <<= 1; p('shift 1'); $val |= 0; p('Or-ed 0'); #Prints in binary with lowest bit to the right side. sub p { printf '%20s : %4d => ', shift, $val; print reverse split '', unpack'b*', pack'c', $val; print "\n"; }