Videos
Byte ordering:
- Some machines decide to store the objects in memory ordered from least significant byte to most, while other machines store them from most to least.
- The byte ordering are made by the two ways:
- Little Endian
- In little Endian, the least significant byte comes first.
- Big Endian
- In big Endian, the most significant byte comes first.
- Little Endian
Example:
The example for find the little-endian and big-endian for hexadecimal value is shown below:
Here assume that the hexadecimal value is “0x13244860”. Then address range for given ordering byte is “0x200” through “0x203”.
Big Endian for given hexadecimal value is
Little Endian for given hexadecimal value is
Explanation of Solution
Corresponding code from given question:
#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" number.
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" number.
void show_float(float x)
{
//Call show_bytes function float value.
show_bytes((byte_pointer) &x, sizeof(float));
}
//Function to determine byte for "pointer" number.
void show_pointer(void *x)
{
//Call show_bytes function with pointer value.
show_bytes((byte_pointer) &x, sizeof(void *));
}
//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);
}
//Main function.
int main(int argc, char* argv[])
{
//Define the sample number.
int sampleNumber = 682402;
//Call test_show_bytes function.
test_show_bytes(sampleNumber);
return 0;
}
The given program is used to display the byte representation of different program objects by using the casting.
- Define “byte_pointer” using “typedef”.
- It is used to define data type as a pointer to an object of type “unsigned char”.
- The function “show_bytes” is used to display the address of a byte sequence by using the argument that is byte pointer and a byte count.
- Each byte is displayed by “2” digit.
- The function “show_int” is to display the byte representations of object of “int” data type.
- The function “show_float” is to display the byte representations of object of “float” data type.
- The function “show_pointer” is to display the byte representations of object of “void *” data type.
- Test all the data type values by using function “test_show_bytes”.
- Finally, assign the sample number in main function and call the “test_show_bytes” with argument “sampleNumber”.
Byte ordering used by the given machines:
After compiling and running the above code, the following output will be appear
a2 69 0a 00
20 9a 26 49
3c cc e9 18 ff 7f 00 00
From the above output,
- The byte representation for “int” data type is “a2 69 0a 00”.
- The byte representation for “float” data type is “20 9a 26 49”.
- The byte representation for “int *”data type is “3c cc e9 18 ff 7f 00 00”.
The byte ordering used by these machines is “big-endian”.
- Reason:
- Consider, the byte representation of “int” value is “a2 69 0a 00”.
- From this, the value is ordered from most significant byte to least significant byte. Hence, it is referred as big-endian.
Want to see more full solutions like this?
Chapter 2 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Degarmo's Materials And Processes In Manufacturing
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out With Visual Basic (8th Edition)
- Step 1: Encryption Algorithm Implementation Choose one symmetric encryption algorithm from the following list: AES, DES, IDEA, Blowfish, RC4, RC5, or RC6. Provide a brief overview of the algorithm, including its history, key features, and typical use cases. Implement the chosen encryption algorithm (in any language you wish). Do NOT use a library or package that already has an implementation of the encryption algorithm in question. NOTE: IT IS NOT THE NORM TO CREATE YOUR OWN IMPLEMENTATION OF AN ENCYRPTION ALGORITHM. THIS IS FOR LEARNING PURPOSES ONLY. IT IS CONSIDERED HIGHLY INSECURE TO DO THIS IN A REAL-WORLD APPLICATION BECAUSE YOUR IMPLEMENTATION MIGHT BE FLAWED. Step 2: Message Encryption Create a plaintext message that will be encrypted. The message should be meaningful and at least 100 characters long. Encrypt the plaintext message using the chosen algorithm, resulting in ciphertext. Step 3: Simulated Network Transmission: Set up a simple client-server architecture using socket...arrow_forwardExercises 7 1) Find A+ and A' if A= 2) Find a basis for the 2 2 3 -1 2 G ( 3 row space of 3 4 following matrix: 3) Find the rank of ( 2 1 3 ( 2 3 C 3 c O -1 2 14-1 each matrip 1-12 b) 3-3 +6 C) 5 1 -2 24 6 4 3 4) what is relationship between rank (A) and rank (-A)? Between rank (A) and rack (αA)? what is relationship between rank (A), a rana (B) and rank (A+B) ?arrow_forwardProblem 2 (from the textbook). ■しかく■しかく P4.2 Mean and standard deviation. Write a program that reads a set of floating-point data values. Choose an appropriate mechanism for prompting for the end of the data set. When all values have been read, print out the count of the values, the average, and the standard deviation. The average of a data set (x1,...,x,) is x=Σx;/n, where Ex=x1++x, is the sum of the input values. The standard deviation is Σ(x-x)2 n-1 However, this formula is not suitable for the task. By the time the program has computed x, the individual x; are long gone. Until you know how to save these values, use the numerically less stable formula Σ*-Σ» n-1 You can compute this quantity by keeping track of the count, the sum, and the sum of squares as you process the input values. Notes: 1. The standard deviation computed according to these formulas is called the "sample standard deviation," i.e. an estimate for the true standard deviation computed with the assumption that the...arrow_forward
- Write a C++ program that reads in three strings and sorts them lexicographically. After the sorting, print out the string in sorted order. You can't call std::sort(), of course, since that would solve the whole problem already. However, you're welcome to look up "C++ string comparison operations" and use those operations. Go through the following steps: 1. Define an array of 3 strings, called strings, in main(), like this: string strings [3]; 2. Ask the user to input 3 strings, each one on a line. Use getline (cin, strings [i]) to read the 3 strings (lines) in a for loop. 3. Write a void swap (string &, string &) function that swaps the two strings given to it as reference parameters. This should be familiar to you. 4. using if statements, string comparison operations, and your swap () function, write code that will sort the 3 strings into ascending lexicographical order. 5. Test the code on all 6 possible permutations of 3 strings, and report on the test results. Include screenshots...arrow_forwardProblem 3. In this problem we'll come up with a sensible, legitimate way of verifying and using useful information from an AI summary found on the Web and learn a few technical things along the way. To do this, let's say you want to know how fast your C++ code works. Step 1: Look up online for ways to time a code snippet written in C++. Tell me in one or two sentences what you found. Step 2: Pick one favorite timing solution, Find out how to make your code "sleep" (do nothing) for a period of time that you can specify. Sometimes this information shows up in the same document on timing your code as way to construct test code. Again tell me in one sentence what you found. Step 3: Using the information found out on steps 1 and 2, write and run and report on code for timing a period of 1/10 sec., 1 sec., and 7 seconds. Step 4. The Fibonacci numbers are defined as F(1) = 1, F(2) = 1, and for n>= 3, F(n) = F(n-1) + F(n-2), Wrire a recursive program to compute the fibonacci numbers. Time the...arrow_forwardwrite in verliog coding language.arrow_forward
- write in C++ languagearrow_forward■しかく■しかく■しかく P4.4 Factoring of integers. Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 150, the program should print 2355arrow_forward3) Is this a subspace of Pr? 2 K. Jar+ax ave2 (a, +20+9=4) 3 4) which of these sets spans R ? That is, which of these sets has the property theet as a any three-tall vector can be expressed Suitable linear combination of the Eets elements? a) b) C) 5 10.0.3) -10.0.0.91arrow_forward
- Using a 4-bit down counter with LD and CNT signals, design a 4-bit timer with a count out and terminal count warning. The terminal count should be high whenever the timer reaches zero and expires. After expiring, the timer should automatically reload and continue counting down. The timer should have two control signals: enable and load. When enabled, the timer should operate. When load is asserted, a new count down value should be loaded into the timer. If both, or neither, control signal is asserted, the timer should not operate.arrow_forwardPlease Provide Accounting Question Solution with Financial methodarrow_forwardActivity A 1. In a CPM network, the critical path includes five activities. Their durations are tabulated next. Optimistic (t) 2 Duration (Days) Most likely (tm) Pessimistic (t2) 4 7 B 5 8 14 C 4 6 8 Ꭰ 2 2 2 E 7 10 21 Compute the following values: • The probability that the project will finish by the end of day 32. • The probability that the project will finish no later than the 35th day. The probability that the project will finish on the 32nd day. What are the lower and upper project durations for a 90% confidence interval?arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY