Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Subtract 2 hexadecimal numbers

by dwm042 (Priest)
on Feb 21, 2014 at 20:11 UTC ( [id://1075779]=note: print w/replies, xml ) Need Help??


in reply to Subtract 2 hexadecimal numbers

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.

Log In?
Username:
Password:

What's my password?
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2026-04-13 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.