Advertisement
Guest User

extra_numeral_systems

a guest
Sep 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. int findWhereIsChar(char forSearch, char * source){
  7. for (int i = 0; i < sizeof(source); i++){
  8. if (source[i] == forSearch)
  9. return i;
  10. }
  11. return -1;
  12. }
  13. char * ns_convert(char * dest, const char * source, unsigned int sourceBase, unsigned int destBase){
  14. char *strcpy (char *dest, const char *source);
  15. char * buffer = dest;
  16. /*check ifs valid*/
  17. char * numerics = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  18. int valid = 1; /*logical value*/
  19.  
  20. for (int i = 0; i < sizeof(buffer); i++){
  21. if((char)buffer[i] != '.')
  22. if(findWhereIsChar(buffer[i], numerics) >= sourceBase)
  23. valid = 0;
  24. }
  25. if (valid){
  26. if (sourceBase != destBase){
  27. if (sourceBase != 10){
  28. /*convert to decimal*/
  29. int j = 0;
  30. int sumDec = 0;
  31. for (int i = sizeof(source); i >= 0; i--){
  32. sumDec += findWhereIsChar(buffer[i], numerics)*(sourceBase^(sizeof(buffer)-i));
  33. }
  34. sprintf (dest, "%d", sumDec);
  35. }
  36. if (destBase != 10){
  37. /*convert from decimal*/
  38. }
  39. }
  40. }
  41. return dest;
  42. }
  43. int main(){
  44. char buf[99];
  45. char * result = ns_convert(buf, "9", 12, 10);
  46. puts(result);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement