#!/usr/bin/perl # # Illustrates binary operators in Perl. # # Author: Prabakar, School of Computng and Information Sciences, FIU # prabakar@cis.fiu.edu # 4/7/2009 # $num1 = 12; # binary: 000...001100 => 12 $twiceNum1 = $num1 << 1; # resulting binary: 000...011000 => 24 print "After left shift the value $num1 by one bit, the new value is $twiceNum1 \n"; $num2 = 770; # binary: 000... 0011 0000 0010 => 770 $twiceNum2 = $num2 >> 8; # resulting binary: 000... 0000 0000 0011 => 3 print "After right shift the value $num2 by eight bits, the new value is $twiceNum2 \n"; $num3 = 3; # binary: 000... 0000 0011 $num4 = 5; # binary: 000... 0000 0101 $num5 = $num4; $num5 |= $num3; # resulting binary: 000... 0000 0111 => 7 print "After performing binary OR on 3 and 5, the new value is $num5 \n"; $num6 = $num4; $num6 &= $num3; # resulting binary: 000... 0000 0001 => 1 print "After performing binary AND on 3 and 5, the new value is $num6 \n"; $num7 = $num4; $num7 ^= $num3; # resulting binary: 000... 0000 0110 => 6 print "After performing binary XOR on 3 and 5, the new value is $num7 \n"; $num8 = ~$num3; #resulting binary: 111... 1111 1100 => 4294967292 (unsigned int) print "After performing binary negation on 3, the new value is $num8 \n"; exit(0);