### Re: Subtract 2 hexadecimal numbers

by dwm042 (Priest)
 on Feb 21, 2014 at 20:11 UTC Need Help??

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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1075779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-03 18:19 GMT
Voting Booth?
My favourite way to spend a leap day ...

Results (29 votes). Check out past polls.