in reply to Re: Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl
in thread Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl

Thanks for the solution. I am actually new to perl and just came up with that weird way to get that output. ;-) But I think the answer is in decimal. After getting these output I added that to an array using the following code  push @strobes,$x; But after that I want to AND(logical) it using a given value. Eg. 00001111--->(offset 3)---> 00001000 11111111--->(offset 2)---> 11111100 I tried to perform any operation on these values but it's treating the values as decimal eg. 00001110-1=1109 Any suggestion on how to perform the logical AND operation.
  • Comment on Re^2: Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl
  • Download Code

Replies are listed 'Best First'.
Re^3: Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl
by bliako (Abbot) on Nov 17, 2018 at 11:40 UTC
    use strict; use warnings; # you can declare a nunber in many different formats. # see https://perldoc.perl.org/perlnumber.html # my $N1 = 0b11010111; my $N2 = 0b10110100; # or $N2 = 180; # or $N2 = 0xb4 # logical *bitwise=bit-by-bit* AND: (and not &&), btw OR is | my $N1_AND_N2 = $N1 & $N2; # you can print a number in many different formats # by default it prints in decimal print "Decimal notation: $N1 AND $N2 = $N1_AND_N2\n"; # but youn change the print format using printf (C-like): printf "Binary notation: %b AND %b = %b\n", $N1, $N2, $N1_AND_N2; printf "Hex notation: %x AND %x = %x\n", $N1, $N2, $N1_AND_N2;

    bw, bliako