Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: bitwise opetator and arithemic

Status
Not open for further replies.

TheEyez81

Technical User
Apr 11, 2007
7
US
Hi,

I have been looking at this for a while now but haven't found a solution to this.

$aA -> really long hex value (128 characters)
$aB -> small decimal number
$aC -> small decimal number

$result = $aA+$aB ^ $aC+3;

I can not get this to work out correctly due to the size of $aA. Does anyone have any suggestion?
 
Use the Math::BigInt module. I would suggest that you use parenthesis to ensure that your order of operations is what you expect. Nevertheless, here is the code so modified:

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]Math::BigInt[/green][red];[/red]

[black][b]use[/b][/black] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$aA[/blue] = Math::BigInt->[maroon]new[/maroon][red]([/red][red]"[/red][purple]0x100000000000000000000000000000000000000000000[/purple][red]"[/red][red])[/red][red];[/red] [gray][i]# really long hex value (128 characters).  Ok maybe only about 40 characters.[/i][/gray]
[black][b]my[/b][/black] [blue]$aB[/blue] = Math::BigInt->[maroon]new[/maroon][red]([/red][red]"[/red][purple]17[/purple][red]"[/red][red])[/red][red];[/red] [gray][i]#small decimal number[/i][/gray]
[black][b]my[/b][/black] [blue]$aC[/blue] = Math::BigInt->[maroon]new[/maroon][red]([/red][red]"[/red][purple]5[/purple][red]"[/red][red])[/red][red];[/red] [gray][i]#small decimal number[/i][/gray]

[black][b]my[/b][/black] [blue]$result[/blue] = [blue]$aA[/blue] + [red]([/red][blue]$aB[/blue] ^ [blue]$aC[/blue][red])[/red] + [fuchsia]3[/fuchsia][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]'[/red][purple]as hex=[/purple][red]'[/red] . [blue]$result[/blue]->[maroon]as_hex[/maroon][red]([/red][red])[/red] . [red]"[/red][purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[gray][i]# Output: as hex=0x100000000000000000000000000000000000000000017[/i][/gray]

[black][b]print[/b][/black] [red]'[/red][purple]as str=[/purple][red]'[/red] . [blue]$result[/blue]->[maroon]bstr[/maroon][red]([/red][red])[/red] . [red]"[/red][purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[gray][i]# Output: as str=95780971304118053647396689196894323976171195136475159[/i][/gray]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
Core (perl 5.8.8) Modules used :
[ul]
[li]Math::BigInt - Arbitrary size integer/float math package[/li]
[/ul]
[/tt]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top