Sometimes the hex function can be useful.#!/usr/bin/perl use warnings; use strict; #prints "0" becaus 0x30 is "0" in ASCII my $char = "\x30"; #quotes makes $char a "character" # result being the number "0" in ASCII # which translates to numeric 0! print "$char\n"; #prints "0" printf "%08b\n", $char; #still prints "0"!! print "\nNow, 0x30 as a number, not a character\n"; #without the quotes, we have a binary number... my $char2 = 0x30; print "$char2\n"; #prints 48 (decimal 0x30) printf "%08b\n", $char2; #prints "00110000" __END__ 0 00000000 Now, 0x30 as a number, not a character 48 00110000
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @strings=("ab30ff","30","ab1a30"); for (@strings){ $_=hex $_; } foreach my $hex (@strings) { printf "%08b\n", $hex; } __END__ 101010110011000011111111 00110000 101010110001101000110000
In reply to Re: while loop on binary : \x30
by Marshall
in thread while loop on binary : \x30
by sphalaris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |