Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
bartleby

Videos

Question
Book Icon
Chapter 2, Problem 2.55HW
Expert Solution & Answer
Check Mark
Program Plan Intro

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.

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

0x200 0x201 0x202 0x203
13 24 48 60

Little Endian for given hexadecimal value is

0x200 0x201 0x202 0x203
60 48 24 13

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Name: Student #: Practical Assessment Three This test is out of 10 points. The test duration is 100 minutes. If you follow the recommended times, you will finish 10 minutes early. Please put your name on each page. Note that you are entitled to one tip from your professor (in addition to any clarifying questions). You do not need to include comments. Here is some useful java syntax: int q = 5% 2; .nextDouble() int x = y + 1; .nextLine() -pow() .next() double r = 7 * 7; public static void main(String[] args){} import java.util.Scanner; = new Scanner(System.in); .nextInt() .sqrt() Scanner input .abs() j=4; .equals() public class ClassName{} System.out.println(); System.out.printf(); int j-1/2; if 00 if}else if(){}else{} while (x+y>z){} do} while(x + y>z); .hasNext() .hasNextInt() .hasNextDouble() static la) b) return private public Write a class to represent a Fish. It should have the fields species, age and maxSpeed. It should have getters and setters for all of these. It should have...
2. Fill in the test plan for the following code. Assume code runs as expected and make sure to represent ALL distinct code execution paths. Note that the code may loop and more than one thing may print. If there is an infinite loop, write the first few elements and then write 'infinite loop'. (1.5 points 20 mins) public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); public static String methodOne(String s) { returns + "s"; int input = 3; do{ System.out.println(methodOne("a")); } if (keyboard.hasNextInt()) { } input keyboard.nextInt(); }else { keyboard.nextLine(); } if (input 1) methodThree(); }while(input methodTwo(2) && input < methodTwo(3)); System.out.println(methodOne("b")); public static int methodTwo(int q){ return q* 2; public static void methodThree() { System.out.println("c"); } } Input Expected Output Actual Output Description Observations
Case study II: Digital Sustainability in South Africa Background South Africa is under pressure to transition to a more sustainable and digitally enabled economy. Climate change, energy insecurity, and social inequality intersect with rapid technological change. In 2024, Ubuntu Energy, a Johannesburg-based energy company, launched an ambitious "Digital Green Transition" strategy. The plan includes: Deploying IoT-enabled smart meters in urban and rural communities to monitor and optimise electricity use. Using AI-driven predictive analytics to forecast demand and integrate renewable energy sources into the grid. Exploring digital twins to simulate operations of new solar and wind farms before construction. However, Ubuntu Energy faces serious challenges: The digital divide in rural areas threatens inclusivity. Legacy IT infrastructure and weak digital literacy limit adoption. Some executives question whether the strategy is just "digital vanity" (buzzwords without measurable...

Chapter 2 Solutions

Computer Systems: A Programmer's Perspective (3rd Edition)

Chapter 2.1, Problem 2.11PP Chapter 2.1, Problem 2.12PP Chapter 2.1, Problem 2.13PP Chapter 2.1, Problem 2.14PP Chapter 2.1, Problem 2.15PP Chapter 2.1, Problem 2.16PP Chapter 2.2, Problem 2.17PP Chapter 2.2, Problem 2.18PP Chapter 2.2, Problem 2.19PP Chapter 2.2, Problem 2.20PP Chapter 2.2, Problem 2.21PP Chapter 2.2, Problem 2.22PP Chapter 2.2, Problem 2.23PP Chapter 2.2, Problem 2.24PP Chapter 2.2, Problem 2.25PP Chapter 2.2, Problem 2.26PP Chapter 2.3, Problem 2.27PP Chapter 2.3, Problem 2.28PP Chapter 2.3, Problem 2.29PP Chapter 2.3, Problem 2.30PP Chapter 2.3, Problem 2.31PP Chapter 2.3, Problem 2.32PP Chapter 2.3, Problem 2.33PP Chapter 2.3, Problem 2.34PP Chapter 2.3, Problem 2.35PP Chapter 2.3, Problem 2.36PP Chapter 2.3, Problem 2.37PP Chapter 2.3, Problem 2.38PP Chapter 2.3, Problem 2.39PP Chapter 2.3, Problem 2.40PP Chapter 2.3, Problem 2.41PP Chapter 2.3, Problem 2.42PP Chapter 2.3, Problem 2.43PP Chapter 2.3, Problem 2.44PP Chapter 2.4, Problem 2.45PP Chapter 2.4, Problem 2.46PP Chapter 2.4, Problem 2.47PP Chapter 2.4, Problem 2.48PP Chapter 2.4, Problem 2.49PP Chapter 2.4, Problem 2.50PP Chapter 2.4, Problem 2.51PP Chapter 2.4, Problem 2.52PP Chapter 2.4, Problem 2.53PP Chapter 2.4, Problem 2.54PP Chapter 2, Problem 2.55HW Chapter 2, Problem 2.56HW Chapter 2, Problem 2.57HW Chapter 2, Problem 2.58HW Chapter 2, Problem 2.59HW Chapter 2, Problem 2.60HW Chapter 2, Problem 2.61HW Chapter 2, Problem 2.62HW Chapter 2, Problem 2.63HW Chapter 2, Problem 2.64HW Chapter 2, Problem 2.65HW Chapter 2, Problem 2.66HW Chapter 2, Problem 2.67HW Chapter 2, Problem 2.68HW Chapter 2, Problem 2.69HW Chapter 2, Problem 2.70HW Chapter 2, Problem 2.71HW Chapter 2, Problem 2.72HW Chapter 2, Problem 2.73HW Chapter 2, Problem 2.74HW Chapter 2, Problem 2.75HW Chapter 2, Problem 2.76HW Chapter 2, Problem 2.77HW Chapter 2, Problem 2.78HW Chapter 2, Problem 2.79HW Chapter 2, Problem 2.80HW Chapter 2, Problem 2.81HW Chapter 2, Problem 2.82HW Chapter 2, Problem 2.83HW Chapter 2, Problem 2.84HW Chapter 2, Problem 2.85HW Chapter 2, Problem 2.86HW Chapter 2, Problem 2.87HW Chapter 2, Problem 2.88HW Chapter 2, Problem 2.89HW Chapter 2, Problem 2.90HW Chapter 2, Problem 2.91HW Chapter 2, Problem 2.92HW Chapter 2, Problem 2.93HW Chapter 2, Problem 2.94HW Chapter 2, Problem 2.95HW Chapter 2, Problem 2.96HW Chapter 2, Problem 2.97HW

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The reason of increase of cutting force Fc with increasing feed or DOC.

Degarmo's Materials And Processes In Manufacturing

Program segment is a step by step procedure of programming language that stores the data state of program which...

Computer Science: An Overview (13th Edition) (What's New in Computer Science)

Hence, the correct answer is option "C".

Starting Out with C++ from Control Structures to Objects (9th Edition)

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Computer Networking: A Top-Down Approach (7th Edi...
    Computer Engineering
    ISBN:9780133594140
    Author:James Kurose, Keith Ross
    Publisher:PEARSON
    Text book image
    Computer Organization and Design MIPS Edition, Fi...
    Computer Engineering
    ISBN:9780124077263
    Author:David A. Patterson, John L. Hennessy
    Publisher:Elsevier Science
    Text book image
    Network+ Guide to Networks (MindTap Course List)
    Computer Engineering
    ISBN:9781337569330
    Author:Jill West, Tamara Dean, Jean Andrews
    Publisher:Cengage Learning
    Text book image
    Concepts of Database Management
    Computer Engineering
    ISBN:9781337093422
    Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
    Publisher:Cengage Learning
    Text book image
    Prelude to Programming
    Computer Engineering
    ISBN:9780133750423
    Author:VENIT, Stewart
    Publisher:Pearson Education
    Text book image
    Sc Business Data Communications and Networking, T...
    Computer Engineering
    ISBN:9781119368830
    Author:FITZGERALD
    Publisher:WILEY
    What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I; License: Standard YouTube License, CC-BY
    Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U; License: Standard Youtube License