Accessing Individual elements of an Array

Viewed 40
#!/usr/bin/env perl

use warnings;    

my $value =  hex ( 'FFFFF' );

print "Dec: ",$value,"\n";
printf ( "Hex: %X\n", $value );
my $binval = sprintf ( "Binary: %0*b\n",28, $value );

print $binval;
my @binval_arr = split('', $binval, 28);
print "Size: ",scalar @binval_arr,"\n";

print "\$binval_arr[5] = $binval_arr[5]\n";

output looks like this

Dec: 1048575

Hex: FFFFF

Binary: 0000000011111111111111111111

Size: 28

$binval_arr[5] = y

I don't understand from where it's getting the Y (maybe ASCII) but the location I'm trying to access has only one bit.

1 Answers

The problem was with the conversion from hex to binary. It took the BINARY string too.

Fix is my $binval = sprintf ( "%0*b\n",28, $value );

Related