security/nss/lib/freebl/mpi/utils/hex2dec.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/freebl/mpi/utils/hex2dec.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +/*
     1.5 + *  hex2dec.c
     1.6 + *
     1.7 + *  Convert decimal integers into hexadecimal
     1.8 + *
     1.9 + * This Source Code Form is subject to the terms of the Mozilla Public
    1.10 + * License, v. 2.0. If a copy of the MPL was not distributed with this
    1.11 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.12 +
    1.13 +#include <stdio.h>
    1.14 +#include <stdlib.h>
    1.15 +#include <string.h>
    1.16 +
    1.17 +#include "mpi.h"
    1.18 +
    1.19 +int main(int argc, char *argv[])
    1.20 +{
    1.21 +  mp_int  a;
    1.22 +  char   *buf;
    1.23 +  int     len;
    1.24 +
    1.25 +  if(argc < 2) {
    1.26 +    fprintf(stderr, "Usage: %s <a>\n", argv[0]);
    1.27 +    return 1;
    1.28 +  }
    1.29 +
    1.30 +  mp_init(&a); mp_read_radix(&a, argv[1], 16);
    1.31 +  len = mp_radix_size(&a, 10);
    1.32 +  buf = malloc(len);
    1.33 +  mp_toradix(&a, buf, 10);
    1.34 +
    1.35 +  printf("%s\n", buf);
    1.36 +
    1.37 +  free(buf);
    1.38 +  mp_clear(&a);
    1.39 +
    1.40 +  return 0;
    1.41 +}

mercurial