Bit position

This is an example how to print the Bit position of a value.

use strict;


sub printBits {
my $count=0;
for(reverse split//,sprintf("%b",$_[0]))
{print "Bit position: @{[++$count]}. value @{[1<<($count-1)]}$/"x!!$_;}

And we see for 5 we get position 1 and 3, and the values 1 and 4 result at 5.

sh-4.2# perl
Bit position: 1. value 1
Bit position: 3. value 4

3 thoughts on “Bit position”

  1. Hello, i believe that i noticed you visited my web site so i came
    to return the want?.I’m trying to in finding issues to enhance my website!I assume its good enough to
    make use of some of your concepts!!

  2. Hello, i think that i saw you visited my website so i came to “return the
    favor”.I am trying to find things to enhance
    my website!I suppose its ok to use a few of your ideas!!

  3. This is very interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your magnificent post.

    Also, I’ve shared your site in my social networks!

Leave a Reply

Your email address will not be published.

four + 15 =