Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
How would you convert a hexadecimal string, like "661efdf2e3b19f7c045f15" to the decimal string "123456789123456789123456789"?
Thanks in advance!
Using GMP you can assign the hex number to an "mpz_t" the GMP integer value. Here's an example.
#include <gmp.h>
int main(int argc, char** argv) {
mpz_t integer;
mpz_init(integer);
mpz_set_str(integer, "661efdf2e3b19f7c045f15", 16); //16 is the number base
gmp_printf("Your number is: %Zd\n", integer); //Outputs "Your number is: 123456789123456789123456789"
return 0;
}
GMP comes automatically with some linux distros but if you don't have it, you can download it here.
Hope this helps!
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Write a C program to convert a number in scientific notation to its equivalent decimal form :
Given
8.3e+2 output = 830
2.E-1 output = 0.2
4.3E2 output = 430
Is there any inbuilt library or function in C/C++ which can do this?
or one will have to write his own code, in that case, any easy way to achieve this?
try this
#include <iostream>
#include <string>
int32_t main(int32_t argc, char *argv[]) {
std::string str = "8.3e+2";
std::cout << std::stod(str) << std::endl;
return EXIT_SUCCESS;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm having trouble finding what does %XX mean in C
an example would be like: printf("%XX\n", num);
edit: num is an int
print num converted to unsigned int as a hexadecimal number and then print char 'X'
In a printf format string, %XX is %X followed by X.
The %X says to format an unsigned int argument as hexadecimal, using uppercase (ABCDEF for the “digits”).
The X is simply a literal X that says to print an “X” after the hexadecimal numeral.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I just started programming and have a question. I have a example input from command line: "number:10" which is "number:" followed by a number. I want to check if the character after "number:" is a number:
int main(int argc, char **argv)
{
if(isdigit(*argv[2]+7)){
printf("correct");
}
return 0;
}
It doesn't work. How can I read only the number in the input string?
*argv[2] is 'n'. *(argv[2]+7) is correct
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Write a C program that reads lines containing floating point values of type double one per line from the standard input ( e.g. using scanf ), converts those values to integers and then prints those values as right justified integers in a 20-character wide field one per line on the standard output.
#include <stdio.h>
My biggest problem is I don't know where to start. Any tips and help would be appreciated.
The concept is to TYPECAST the float to an integer.
The loop here is for multiple values if you want.
This is the program. I hope this helps; it runs as you want.
#include <stdio.h>
int main()
{
float n;
int t;
//loop here
scanf("%f", &n);
t = (int)n;
printf("%20d", t);
// end loop here
return 0;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to know if there is any function in the C language which can convert base of decimal number binary or Decimal to Hexadecimal or etc.
You can try this..
int convert(int number,int base){
if(number == 0 || base==10)
return number;
return (number % base) + 10*convert(number / base, base);
}
int main () {
int a;
scanf("%d",&a);
//Lets convert 123 in decimal to octal
printf("%d\n",convert(123, 8));
return 0;
}
Let me know if this helps.. :)
There is no standard libraries or functions to do that
You can always write a small function to do your calculations.. It won't be hard to find codes (If you don't wanna write) but I suggest to write them your self with your basic knowledge on number conversions..