HI, I am new to perl. I was converting the decimal to binary for numbers below 256. I got a way to do this:
I think its ok. But I am wondering if the number is greater than 256 ??#!/usr/bin/perl use warnings; use strict; print " Enter a number between 0 to 256 : "; my $dec = <STDIN>; my $a = ($dec & 128) <=> 0; my $b = ($dec & 64) <=> 0; my $c = ($dec & 32) <=> 0; my $d = ($dec & 16) <=> 0; my $e = ($dec & 8) <=> 0; my $f = ($dec & 4) <=> 0; my $g = ($dec & 2) <=> 0; my $h = ($dec & 1) <=> 0; print " The entered decimal number in binary is : ",$a.$b.$c.$d.$e.$f. +$g.$h," \n";
In reply to decimal to binary by divyaimca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |