Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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!

In reply to vexed by the hex! by holandes777

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (5)
    As of 2019-11-14 06:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (76 votes). Check out past polls.

      Notices?