Concept explainers
Explanation of Solution
Corresponding modified code for “show_bytes”:
#include <stdio.h>
//Define variable "byte_pointer" in char datatype.
typedef unsigned char* byte_pointer;
//Function definition for show_bytes.
void show_bytes(byte_pointer start, size_t len)
{
//Declare variable "i" in int data type.
int i;
/* "For" loop to determine byte representation in hexadecimal */
for (i = 0; i < len; i++)
//Display each bytes in "2" digits hexadecimal value.
printf(" %.2x", start[i]);
printf("\n");
}
//Function to determine byte for "int" data type value.
void show_int(int x)
{
//Call show_bytes function with integer value.
show_bytes((byte_pointer) &x, sizeof(int));
}
//Function to determine byte for "float" data type value.
void show_float(float x)
{
//Call show_bytes function float value.
show_bytes((byte_pointer) &x, sizeof(float));
}
//Function to determine byte for "pointer" value.
void show_pointer(void *x)
{
//Call show_bytes function with pointer value.
show_bytes((byte_pointer) &x, sizeof(void *));
}
//Function to determine byte for "short" data type value.
void show_short(short x)
{
//Call show_bytes function with short int value.
show_bytes((byte_pointer) &x, sizeof(short));
}
//Function to determine byte for "long" data type value.
void show_long(long x)
{
//Call show_bytes function with long value.
show_bytes((byte_pointer) &x, sizeof(long));
}
//Function to determine byte for "double" data type value.
void show_double(double x)
{
//Call show_bytes function with double value.
show_bytes((byte_pointer) &x, sizeof(double));
}
//Test all show bytes.
void test_show_bytes(int val)
{
//Define variables.
int ival = val;
float fval = (float) ival;
int *pval = &ival;
//Call function.
show_int(ival);
show_float(fval);
show_pointer(pval);
//Define variables.
short sval = (short) ival;
long lval = (long) ival;
double dval = (double) ival;
//Call function.
show_short(sval);
show_long(lval);
show_double(dval);
}
//Main function.
int main(int argc, char* argv[])
{
//Define the sample value.
int sampleValue = 1024;
//Call test_show_bytes function.
test_show_bytes(sampleValue);
return 0;
}
The given program is used to display the byte representation of different program objects by using casting...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- Write this program in C programming language. Also provide a screenshot that it is working.Here is the question:Write a program that determines the three largest elements among inputed numbers.arrow_forwardWrite a program in C++ that can perform encryption and decryption using an arbitrary substitution cipher. In this case, the encrpyion array is a random shuffling of the letters in the alphabet. Your program should generate a random encryption array, its corresponding decryption array, and use these to encode and decode the message.arrow_forwardWrite a C program that uses arrays and functions to implement a calculator for twooperands. Your calculator must have five principal operations, addition ( ), subtraction ( ),division ( ), multiplication ( ), and power ( ). In the beginning of the program, show the menuof operators to the user. When the user selects one of the operators, your program gets the valuesfor operand 1 and operand 2 from the user and saves them into an array. Then pass the array to thesuitable function to calculate the result. The operating functions must return the value to the mainprogram. The calculation stops when the user press “x”. Use a global variable to save the result oflast operation. Anytime that the user types “M”, the program shows the result of last operation.hint: Each mathematic operation must be a separate function. Your main program calls those functions.arrow_forward
- Please answer in Python or Java: In this assignment, you will do an implementation of the Huffman Code. If you have the Data Structures book for this class, on pages 415-421 is the theory for encoding a String using the Huffman Code. There is also a PDF of these pages on the class website. Your task is to develop a proof of concept of the Huffman Code and demonstrate it by taking a String and encoding it. The Huffman Code requires knowledge of a few data structure concepts discussed in class: Priority Queues Binary Trees Recursion Arrays and/or Linked Lists In your program, you will demonstrate an understanding of all these concepts by developing your own priority queue, node, binary tree, array and/or linked list, and use of recursion to support the Huffman Code encryption algorithm. Read through the theory of the Huffman Code in the text and then write a program that can take a String and encrypt it. For example, given a string “Hello World”, the program should apply the…arrow_forwardslove the problem through c++ programing language with standard output. Take 10 integer inputs from the user and store them in an array. Again ask the user to give a number. Now, tell the userwhether that number is present in the array or not. write code in c++ and also show outputarrow_forwardIn c++ , perform data searching using linear and binary search. ( Drop code in words , explain the code and drop the screenshot of output as well )arrow_forward
- Language is C++ Rare Collection. We can make arrays of custom objects just like we’ve done with ints and strings. While it’s possible to make both 1D and 2D arrays of objects (and more), for this assignment we’ll start you out with just one dimensional arrays: directions as follows in the picturesarrow_forwardHi! I need some help writing some code in C language (NOT C++/Java/Python!). How can I merge two different sentences (defined by user input - stored in arrays?) with alternating letters, print it, and then print it backwards? I would also like to remove any gaps or spaces before the sentences are merged. For example: Sentence 1 = I like cake Sentence 2 = I like donuts Merged sentences = IIlliikkeecdaokneuts Backwards merged sentences = stuenkoadceekkiillIIarrow_forwardUse C Language Write a program that reads two matrices of integers. It then generates the sum and difference of the two matrices. The sum of the two matrices of the same size is a matrix with elements that are the sums of the corresponding elements of the two given matrices. Addition is not defined for matrices of different sizes. If A and B are matrices of the same size, then we define subtraction as follows: A – B = A + (-B). Thus, to subtract matrix B from matrix A, we simply subtract corresponding elements.arrow_forward
- Take an array having size less than 10 and write a C++ program to display its elements in the reverse order.arrow_forwardImplement the charAt function of Java in C++. Function takes two argument i.e. string and integer i and return the character at index i in the string. Function returns NULL if Integer i is not in valid range.arrow_forwardWrite a c++ program that determines whether or not a string of alphanumeric characters is a palindrome. Ignore any whitespace characters or punctuation when processing the string. You will be required to demonstrate pointer math and dereferencing. You will be required to separate your interface from your implementation; you must have a header file (.h) for your interface, and a source file (.cpp) for your implementation. Be sure to perform data validation on your input to prevent buffer overflows. Your code should present the user with prompts similar to the following: (image included) Here are some example palindromes you can test with: Mr. Owl ate my metal wormDo geese see God?Was it a car or a cat I saw?Murder for a jar of red rumA nut for a jar of tunaGo hang a salami, I'm a lasagna hog!arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education