1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Daniel [21]
3 years ago
11

suppose we number the bytes in a w-bit word from 0 (less significant) to w/8-1 (most significant). write code for the followign

c function, which will return an unsigned value in which byte i of argument x has been replaced by byte b:unsigned replace_byte (unsigned x, int i, unsigned char b);
Engineering
1 answer:
sammy [17]3 years ago
8 0

Solution:

typedef  unsigned  char  *byte_pointer;

static int  int_of_bit  (byte_pointer x,  int  loc)

{

                  return(x[loc] << loc*8);

}  

static int  replace_byte(unsigned int a,  int loc,  unsigned int  b)

    unsigned int a_loc = int_of_bit((byte_pointer) &a ,  loc);

    unsigned int b_loc = (b  <<  loc*8);

 

     a  -=  a_loc;

      a  += b_loc;

      return a;

}

Explanation:

This takes two ints in hex format, one with 8 bits (0x00000000) and one with 2 bits (0x00) then places the 2 bit hex into the 8 bit at a given location.

EX:  replace_byte(0x00000000, 1, 0xFF) return 0x0000FF00

First thing first, it looks like you have some mixup:

" one with 8 bits (0x00000000) and one with 2 bits (0x00)*- what you mean is nibble not bits. Each hex character (0-9, A-F) represent 4 bits (16 possible combination), and is called a "nibble".

0x0000000 is 4 bytes. 0x00 is 2 bytes.

Next, you say "takes two ints in hex format" - your function takes two ints in any format. You're just choosing tp express them in hexidecimal. C++ doesn't care if you specify numbers in hex, decimal, octal, binary, etc.

You might be interested in
Water vapor at 5 bar, 320°C enters a turbine operating at steady state with a volumetric flow rate of 0.65 m3/s and expands adia
harina [27]

Answer:

Power = 371.28 kW

Explanation:

Initial pressure, P1 = 5 bar

Final pressure, P2 = 1 bar

Initial temperature, T1 = 320°C

Final temperature, T2 = 160°C

Volume flow rate, V = 0.65m³/s

From steam tables at state 1,

h1 = 3105.6 kJ/kg, s1 = 7.5308 kJ/kgK

v1 = 0.5416 m³/kg

Mass flow rate, m = V/v1

m = 1.2 kg/s

From steam tables, at state 2

h2 = 2796.2 kJ/kg, s2 = 7.6597 kJ/kgK

Power developed, P = m(h1 - h2)

P = 1.2(3105.6-2796.2)

P = 371.28 kW

8 0
4 years ago
I need ideas for what to build because I have some spare wood.
Misha Larkins [42]

Answer:

small guitar with no strings?

Explanation:

it would be fun to make i think

6 0
3 years ago
A ductile hot-rolled steel bar has a minimum yield strength in tension and compression of Syt = 60 kpsi and Syc = 75 kpsi. Using
kow [346]

Answer:

2.135

Explanation:

Lets make use of these variables

Ox 16.5 kpsi, and Oy --14,5 kpsi

To determine the factor of safety for the states of plane stress. We have to first understand the concept of Coulomb-Mohr theory.

Mohr–Coulomb theory is a mathematical model describing the response of brittle materials such as concrete, or rubble piles, to shear stress as well as normal stress.

Please refer to attachment for the step by step solution.

4 0
4 years ago
In almost all cases, touching power lines or coming into contact with energized sources will result in what?
Fynjy0 [20]

Answer:

electrocution

Explanation:

You will end up getting shoked because the electricity is attracted to the water in your body.

6 0
3 years ago
The angle formed between the SAI and the camber line is called the
hichkok12 [17]

Answer:C

Explanation:

8 0
4 years ago
Other questions:
  • The density of oxygen contained in a tank is 2.0 kg/m3 when the temperature is 25 °C. Determine the gage pressure of the gas if
    12·1 answer
  • How to solve this question
    11·1 answer
  • Write multiple if statements
    5·1 answer
  • How to Cancel prescription
    12·1 answer
  • A life cycle assessment (LCA) determines the environmental impact at all stages of a product's life cycle, including production,
    12·1 answer
  • An ocean thermal energy conversion system is being proposed for electric power generation. Such a system is based on the standar
    5·1 answer
  • on the same scale for stress, the tensile true stress-true strain curve is higher than the engineeringstress-engineering strain
    10·1 answer
  • Contrast moral and immoral creativity and innovation<br>​
    12·1 answer
  • What is the purpose of having a ventilation system on board a motorized vessel?.
    8·1 answer
  • A 46.0-g meter stick is balanced at its midpoint (50.0 cm, zero point is a left end of stick). Then a 210.0-g weight is hung wit
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!