|
1 /* |
|
2 * dec2hex.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/. */ |
|
9 |
|
10 #include <stdio.h> |
|
11 #include <stdlib.h> |
|
12 #include <string.h> |
|
13 |
|
14 #include "mpi.h" |
|
15 |
|
16 int main(int argc, char *argv[]) |
|
17 { |
|
18 mp_int a; |
|
19 char *buf; |
|
20 int len; |
|
21 |
|
22 if(argc < 2) { |
|
23 fprintf(stderr, "Usage: %s <a>\n", argv[0]); |
|
24 return 1; |
|
25 } |
|
26 |
|
27 mp_init(&a); mp_read_radix(&a, argv[1], 10); |
|
28 len = mp_radix_size(&a, 16); |
|
29 buf = malloc(len); |
|
30 mp_toradix(&a, buf, 16); |
|
31 |
|
32 printf("%s\n", buf); |
|
33 |
|
34 free(buf); |
|
35 mp_clear(&a); |
|
36 |
|
37 return 0; |
|
38 } |