Computer Science, asked by nasrinmallick6, 6 months ago


The ASCII system is used to convert numbers
from decimal to binary and vice versa.​

Answers

Answered by tiwarishashwat125
2

Answer:

Conversion binary to decimal and vice versa: We multiply each binary digit by its weighted position, and add each of the weighted value together. To convert decimal number into binary number, repeated division by 2 is needed.

Explanation:

Given a number and its base, convert it to decimal. The base of number can be anything such that all digits can be represented using 0 to 9 and A to Z. The value of A is 10, the value of B is 11 and so on. Write a function to convert the number to decimal.

Examples:

Input number is given as string and output is an integer.

Input: str = "1100", base = 2  

Output: 12

Input: str = "11A", base = 16

Output: 282

Input: str = "123",  base = 8

Output: 83  

We strongly recommend you to minimize your browser and try this yourself first.

We can always use the below formula to convert from any base to decimal.

"str" is input number as a string  

"base" is the base of the input number.

Decimal Equivalent is,

 1*str[len-1] + base*str[len-2] + (base)2*str[len-3] + ...

Similar questions