Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A 0 : Base to Decimal Learning Outcomes - - - - - - - - - - - - - - - - -

A0: Base to Decimal
Learning Outcomes
-----------------
1.**Explain** the difference between characters and numbers on a computer.
2.**Use** an array as a lookup table to check for character equality.
3.**Use** an algorithm to translate a number from a different base to decimal.
4.**Develop** a program that **utilizes** this algorithm.
Specifications
--------------
For this assignment you will write a program that can convert numbers written in bases 2 to 16 into their decimal equivalents. The numbers will be prefixed with `0b`,`0q`,`0s`,`0n`,`0z` and `0x`, for example, indicting which base the given input is in.
There's no need to write any code outside of lines 20-27 inside `main()` and the `chars_to_int()` function. // this is a pre-processor directive
#include
// this is a function prototype
int chars_to_int(char*, int);
const char *bases ="__btqpshondlzrfyx";
// this is the main function
int main(int argc, char **argv){
// output usage if incorrect number of command line
// arguments were given
if (argc !=2){
printf("usage: %s 0[btqpshondlzrfyx]
", argv[0]);
return -1;
}
//`chars` is an array of characters
char *chars = argv[1];
// TODO: call `chars_to_int()` with correct arguments
// TODO: output an error if `chars_to_int`
// encountered an error
// print the result
printf("%d
",0);
// exit succefully
return 0;
}
int chars_to_int(char *chars, int base){
// TODO: implement this function to translate
// an array of characters to a decimal number
// TODO: return the result
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago