perl - Multiply hex number result in wrong sequence -


i try multiple 1 hex number 10 , add hex number result weird.

use strict; use warnings;  $address= 0x10000; ( $i =0 ; $i<=499 ; $i++ ) {     $line = hex($i+1)*10;     $new_address = $address + $line;     print $new_address\n; } 

the answer wan should every 15 hex($i+1) should become

hex(15) = f * 10 = f0 10000 + f0 = 100f0 hex(16) = 10 * 10 = 100 10000 + 100 = 10100 

but answer incorrect. calculation wrong?

you should convert hexadecimal representation when printing values,

use strict; use warnings;  $address= 0x10000; (my $i =0 ; $i<=499 ; $i++ ) {     # 10 != 0x10     $line = ($i+1)*0x10;     $new_address = $address + $line;     # print sprintf("%x\n", $new_address);     printf("%x\n", $new_address); } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -