Write the following functions involving a single hex digit. (a) char dec2hexNibb
ID: 3935244 • Letter: W
Question
Write the following functions involving a single hex digit. (a) char dec2hexNibble(n), which given an integer n (where 0 lessthanorequalto n lessthanorequalto 15), returns the corresponding hex character (single digit). (b) int hex2decNibble (char c), which given a hex character (0 - F), returns the corresponding decimal value (c) void hex2binNibble (char c, int binArray []). which given a hex character, returns the corresponding 4-bit binary number (in bin Array). (d) char bin2hexNibble(int binArray[]), which given a 4-bit binary number, returns the corresponding hex digit. Write the following functions involving padding. (a) void padBinary (int N, int binArray[], int numBits), which given a binary array (inBin[] of dimension N) and total number of desired bits numBits. returns the zero-padded array. For example, if N = 5, binArray = (1 0 1 1 0], and numBits = 8, then binArray = [0 0 0 1 0 1 1 0]. (b) int unpadBinary (int N, int binArray []), which given a binary array of dimension N, removes any leading 0's. The number of digits that were removed is returned. Write the function int bin2dec(int N, int binArray []), which given a binary array, returns the equivalent decimal value. (a) Write a program (you can put every thing in main) which given a decimal number, creates the table which shows the steps for how it is converted to decimal. (b) Turn your program into a function called int dec2bin(int dec, int binArray[]) which given a decimal number, sets up the corresponding binary array. Also, it returns (as an int) the number of bits contained in binArray[]. Write the functions: (a) void bin2hex(int N, int binArray[], char hexArray[]) (b) void hex2bin(int N, int binArray[], char hexArray[])Explanation / Answer
These are the 2 functions for a and b of question 6.
#include <stdio.h>
char dec2hexNibble(int n)
{
if(n > 0 && n < 10)
return n + '0';
if(n == 10)
return 'A';
else if(n == 11)
return 'B';
else if(n == 12)
return 'C';
else if(n == 13)
return 'D';
else if(n == 14)
return 'E';
else if(n == 15)
return 'F';
}
int hex2decNibble(char c)
{
if(isdigit(c))
return c - '0';
else if(c == 'A')
return 10;
else if(c == 'B')
return 11;
else if(c == 'C')
return 12;
else if(c == 'D')
return 13;
else if(c == 'E')
return 14;
else if(c == 'F')
return 15;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.