Question

In: Computer Science

A C program that going to accept a single command line arg and convert it to...

A C program that going to accept a single command line arg and convert it to hexadecimal as an array of char that has 16 bits. The array should contain the hex of the int argument. Side note the command line arg is a valid signed int and the program should be able to convert negative numbers.

Solutions

Expert Solution

According to the Question -

here is the program that convert your number in HEXADECIMAL

  
#include<stdio.h>
#include<conio.h>
  
// function to convert decimal to hexadecimal

void decToHexa(int n)
{

// char array to store hexadecimal number

char hexaDeciNum[100];

  

// counter for hexadecimal number array

int i = 0;

while(n!=0)

{

// temporary variable to store remainder

int temp = 0;

  

// storing remainder in temp variable.

temp = n % 16;

  

// check if temp < 10

if(temp < 10)

{

hexaDeciNum[i] = temp + 48;

i++;

}

else

{

hexaDeciNum[i] = temp + 55;

i++;

}

  

n = n/16;

}

  

// printing hexadecimal number array in reverse order

for(int j=i-1; j>=0; j--)
printf("%c",hexaDeciNum[j]);
  
  
}

  
// Driver program to test above function

int main()
{

int n;
printf("Enter a Number to Convert - ");
scanf("%d",&n);

decToHexa(n);

return 0;
}

OUTPUT : -


Related Solutions

A C program that accepts a single command line argument and converts it in to binary...
A C program that accepts a single command line argument and converts it in to binary with array length of 16 bits. The array should contain the binary of the int argument. the program should also convert negative numbers. Side note the command line arg is a valid signed int.
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form: GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Write a C++ program that prints out all of the command line arguments passed to the...
Write a C++ program that prints out all of the command line arguments passed to the program. Each command line argument should be separated from the others with a comma and a space. If a command line argument ends in a comma, then another comma should NOT be added
Use C++ to write a program that reads in a binary string from the command line...
Use C++ to write a program that reads in a binary string from the command line and applies the following (00, 1101) tag-system: if the first bit is 0, deletes the first three bits and append 00; if the first bit is 1, delete the first three bits and append 1101. Repeat as long as the string has at least 3 bits. Try to determine whether the following inputs will halt or go into an infinite loop: 10010, 100100100100100100. Use...
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 1b) Write a C program that reads in a string from the keyboard. Use scanf with the conversion code %s. Recall that the 2nd arg in...
C PROGRAM In Stage 1, you will be implementing the Draw Line command to draw horizontal...
C PROGRAM In Stage 1, you will be implementing the Draw Line command to draw horizontal and vertical lines. The Draw Line command is given four additional integers, which describe two pixels: the start and end pixels of the line. Each pixel consists of two numbers: the index of the row, and the index of the column. For example, the command 1 10 3 10 10 tells your program to draw a line (1), starting at the pixel at row...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT