ccomplement

Why is -9 base 10 equal to a7ffda89 in base 17?


Using Microsoft's implementation of itoa, how do you get "a7ffda89" as the base 17 representation of -9 in base 10? What I am looking for is a description of the algorithm.

Here is the code I used to find out what itoa would return using Microsoft's implementation:

#include "stdafx.h"  
#include <stdlib.h>

int main(int argc, char *argv[])
{
  (void)argc;
  (void)argv;
  char buff[256] = {};
  memset(buff, '0', 256);
  _itoa_s(-9, buff, 256, 17);
  exit(0);
}

Solution

  • From cplusplus.com:

    If base is 10 and value is negative, the resulting string is preceded with a minus sign (-). With any other base, value is always considered unsigned.