2014-06-27 17:11:32 -07:00
|
|
|
package DDG::Goodie::HexToDec;
|
|
|
|
# ABSTRACT: Convert hexidecimal to decimal
|
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2014-06-27 17:11:32 -07:00
|
|
|
use DDG::Goodie;
|
2014-07-03 13:29:16 -07:00
|
|
|
use Math::BigInt;
|
2014-06-27 17:11:32 -07:00
|
|
|
|
2014-12-07 19:08:15 -08:00
|
|
|
triggers query_raw => qr/^\s*0x[0-9a-fA-F]+(?:(?:\s+hex)?\s+(?:in|as|to)\s+(?:dec(?:imal)?|base(?:\s+|-)?10))?\s*$/;
|
2014-06-27 17:11:32 -07:00
|
|
|
|
2014-09-20 13:19:50 -07:00
|
|
|
zci answer_type => 'hex_to_dec';
|
2014-06-30 16:29:34 -07:00
|
|
|
zci is_cached => 1;
|
2014-06-27 17:11:32 -07:00
|
|
|
|
|
|
|
primary_example_queries '0x44696f21';
|
|
|
|
description 'convert hexidecimal to decimal';
|
|
|
|
name 'HexToDec';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/HexToDec.pm';
|
|
|
|
category 'conversions';
|
|
|
|
topics 'math', 'programming';
|
|
|
|
attribution cpan => 'majuscule',
|
2015-01-07 10:37:42 -08:00
|
|
|
github => ['nospampleasemam', 'Dylan Lloyd'],
|
2014-06-27 17:11:32 -07:00
|
|
|
web => ['https://dylansserver.com', 'Dylan Lloyd'] ;
|
|
|
|
|
|
|
|
handle query_raw => sub {
|
2014-09-20 13:00:51 -07:00
|
|
|
return unless (m/0x([0-9a-fA-F]+)/);
|
2014-10-09 06:58:15 -07:00
|
|
|
|
|
|
|
my $hex = $1;
|
2014-07-03 13:29:16 -07:00
|
|
|
my $decimal = Math::BigInt->from_hex($hex);
|
2014-10-09 06:58:15 -07:00
|
|
|
|
|
|
|
return "$hex base 16 = $decimal base 10", structured_answer => {
|
|
|
|
input => ['0x' . $hex],
|
2015-01-09 00:03:10 -08:00
|
|
|
operation => 'Hex to decimal',
|
2014-10-09 06:58:15 -07:00
|
|
|
result => "$decimal", # Quoted for display precision as string.
|
|
|
|
};
|
2014-06-27 17:11:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
0x41414141;
|