http://www.perlmonks.org?node_id=1179502

holandes777 has asked for the wisdom of the Perl Monks concerning the following question:

A hex charater is a hex character or is it?

A) my $indata = ''; B) while ((my $c = $Tty->read(1)) ne "") { $indata .= ($c); } # here + I am bringing in hex chracters one at a time. The unit sends me 0xfc + 0x05 0x11 0x27 and 0x56 C) my $payload = extract_payload($indata); # this syas we have 5 byte +s total, we strip to the length and strip the 2 byte CRC at the end l +eaving 0x11 D) my $prtpayload = unpack "H*", $payload; my $prtstatus = unpack "H*" +, substr($payload,0,1); print "kk: payload=$prtpayload status=$prtsta +tus "; E) my $status = substr($payload,0,1); # in this case it is the only b +yte F) $prtstatus = unpack "H*", $status; my $ordstatus = ord($status); pr +int "kk: status2=$prtstatus status3=$ordstatus "; G) if ( $status eq 0x11 ) { print "ok_0x11 "; } else { print "not_0x11 + "; } # note that I also used == for the comparison "just in case) a +nd had the same results OUTPUT: kk: payload=11 status=11 kk: status2=11 status3=17 not_0x11

here is where I am massively confused:

1) I know, for a fact, from the protocol manual and the channel analyzer, that the unit is sending 0x11

2) The output generated by D and F both indicate it is 0x11 or 17 decimal.

3) Why does "G" say that $status, which is 0x11 is not 0x11?

Thanks you all!