zeroclickinfo-goodies/lib/DDG/Goodie/HexToDec.pm

37 lines
1.1 KiB
Perl
Raw Normal View History

2014-06-27 17:11:32 -07:00
package DDG::Goodie::HexToDec;
# ABSTRACT: Convert hexidecimal to decimal
use strict;
2014-06-27 17:11:32 -07:00
use DDG::Goodie;
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
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 {
return unless (m/0x([0-9a-fA-F]+)/);
2014-10-09 06:58:15 -07:00
my $hex = $1;
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],
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;