Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /*
2 * hex2dec.c
3 *
4 * Convert decimal integers into hexadecimal
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
14 #include "mpi.h"
16 int main(int argc, char *argv[])
17 {
18 mp_int a;
19 char *buf;
20 int len;
22 if(argc < 2) {
23 fprintf(stderr, "Usage: %s <a>\n", argv[0]);
24 return 1;
25 }
27 mp_init(&a); mp_read_radix(&a, argv[1], 16);
28 len = mp_radix_size(&a, 10);
29 buf = malloc(len);
30 mp_toradix(&a, buf, 10);
32 printf("%s\n", buf);
34 free(buf);
35 mp_clear(&a);
37 return 0;
38 }