There are a lot of excellent contributions here. But I thought I could take a crack at this one

#! /usr/bin/perl my $inst1 = ""; while(<DATA>) { chomp; if ( /inst1/ ) { my ( $hex, $etc ) = split "="; $inst1 = $hex; } elsif ( /inst2/ ) { my ( $hex, $etc ) = split "="; my $diff = ($inst1 - hex($hex)) & hex("0x0ffffff"); printf "Diff = %6x hex, and %d decimal.\n", $diff, $diff; } } __DATA__ 0x405d75=inst1 0x405d7a=inst2 0x4035f7=inst1 0x4035f8=inst2 0x4035f8=inst1 0x4035fb=inst2 0x4035fb=inst1 0x4035fc=inst2 0x4035fc=inst1 0x4035fd=inst2 0x405d7a=inst1 0x405d81=inst2

The output is:

C:\scripts>perl hex-and-decimal.pl Diff = bfa286 hex, and 12558982 decimal. Diff = bfca08 hex, and 12569096 decimal. Diff = bfca05 hex, and 12569093 decimal. Diff = bfca04 hex, and 12569092 decimal. Diff = bfca03 hex, and 12569091 decimal. Diff = bfa27f hex, and 12558975 decimal.

David.


In reply to Re: Subtract 2 hexadecimal numbers by dwm042
in thread Subtract 2 hexadecimal numbers by samd

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, details, 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, summary, 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.