I'm trying to convert a "string" which is filled with values from "\x00" to "\xFF" and I would like to know if a special bit is set in a special byte in the string. Therefore I created a small function but it does not work:
sub isBitSetInCtrMsg
{
my $data = shift; # value can be: "\xFF"
my $data_byte_address = shift; # value can be 0-88
my $data_bit_address = shift; # value can be 0-7
my @data_array = split('',$data); #"split string into bytes"
my $data_byte = $data_array[$data_byte_address]; # pick specific byte
$is_set = ($data_byte & (1 << $data_bit_address)); # check if bit is set
return $is_set; # return value
}
I thought it was quit a simple part of my code but the problem is if $data = 0xFF
then everything works fine, but if my data is \xFF
my code doesn't work.
Can anyone tell me why and how can I check this in the correct way?