Is there any dedicated function for converting the binary values to decimal values.
such as (1111 to 15 ) , ( 0011 to 3 ) .
Thanks in Advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, the strtol function has a
baseparameter you can use for this purpose.Here’s an example with some basic error handling:
This correctly parses and prints the integer 25 (which is
11001in binary). The error handling ofstrtolallows noticing when parts of the string can’t be parsed as an integer in the desired base. You’d want to learn more about this by reading in the reference I’ve linked to above.