Here is what I have so far... I check it to make sure all of the arguments are there, then convert it to binary, then display. The problem I am having is converting everything to binary and then displaying it in either sign/mag, 1's, or 2's.
Thanks for your help,
Mike
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
// Check to make sure all of the arguments are inputted, otherwise print invalidUsage()
if (argc != 3){
// Display invalid usage
invalidUsage();
} else {
// Convert the input into binary
long v = convertInput(argv[1], argv[2]);
// Print the output of the conversions
doOutput(v);
}
return 0;
}
int convertInput(char *format, char *value){
// Choose the type of input
if(strcmp(format, "bin") == 0){
// If the input is binary
convertBinary(value);
} else if(strcmp(format, "oct") == 0){
// If the input is octal
convertOctal(value);
} else if(strcmp(format, "dec") == 0){
// If the input is decimal
convertDecimal(value);
} else if(strcmp(format, "hex") == 0){
// If the input is hexadecimal
convertHex(value);
} else {
// If it is none of the above
invalidUsage();
}
}
int invalidUsage(){
// If the input is incorrect, display mynumber usage
printf("Usage: ./mynumber [bin binary number]\n\t\t [oct octal number]\n\t\t [dec decimal number]\n\t\t [hex -hexadecimal number]\n");
}
doOutput(long value){
// Sign/Magnatude output
doOutputSignMag(value);
// One's Complement output
doOutputOnes(value);
// Two's complement output
doOutputTwos(value);
}
int convertBinary(char *str){
}
int convertOctal(char *str){
}
int convertDecimal(char *str){
}
int convertHex(char *str){
}
doOutputSignMag(long value){
}
doOutputOnes(long value){
}
doOutputTwos(long value){
}