Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^5: Decimal to Binary using Bitwise and operator

by roboticus (Chancellor)
on Sep 02, 2017 at 17:25 UTC ( [id://1198585]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Decimal to Binary using Bitwise and operator
in thread Decimal to Binary using Bitwise and operator

Anonymous Monk:

You can save yourself some cut & paste if you do it like:

$ cat pm_1198573.pl #!env perl use strict; use warnings; print "Input a decimal number between 0 and 255: "; my $decimal = <STDIN> + 0; die "Please follow directions!" if $decimal < 0 or $decimal > 255; print "The number $decimal AND ", (1<<$_), " gives us: ", ($decimal & +1<<$_), "\n" for reverse 0 .. 7; $ perl pm_1198573.pl Input a decimal number between 0 and 255: 113 The number 113 AND 128 gives us: 0 The number 113 AND 64 gives us: 64 The number 113 AND 32 gives us: 32 The number 113 AND 16 gives us: 16 The number 113 AND 8 gives us: 0 The number 113 AND 4 gives us: 0 The number 113 AND 2 gives us: 0 The number 113 AND 1 gives us: 1

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found