C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 22, Problem 22.9E

(Unpacking Characters from Unsigned Integers) Using the right-shift operator, the bitwise AND operator and a mask, write function unpackCharacters that takes the unsigned integer from Exercise 22.8 and unpacks it into four characters. To unpack characters from an unsigned four-byte integer, combine the unsigned integer with a mask and right-shih the result. To create the masks, you’ll need to unpack the four characters. left-shift the value 255 in the mask variable by eight bits 0, 1, 2 or 3 times (depending on the byte you are unpacking). Then take the combined result each time and right shift it by eight bits the same number of times. Assign each resulting value to a char variable. The program should print the unsigned integer in bits before it's unpacked, then print the characters in bits to confirm that they were unpacked correctly.

Blurred answer
Students have asked these similar questions
▼ Part A - The effect of an arithmetic shift on signed numbers Let's look at see what happens to signed numbers during a shift operation. As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine. signed int mult_2_to_n (signed int num, int n) { signed int result; result = num << n; printf("%d multiplied by 2^%d %d\n", num, n, result); return result; } Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below…
(Display  patterns using loops) Use nested loops that display the following patterns in two separateprograms: pattern A           Pattern B                      Pattern c 123456                     1                                        3 1        6                  1 2 3                                  3 3 1        6               1 2 3 4 5                            3 3 3 1        6             1 2 3 4 5 6 7                           3 3 1        6          1 2 3 4 5 6 7 8 9                           3 123456
(Integer) Bit Operators. Write a program that takes begin and end values and prints out a decimal, binary, octal, hexadecimal chart like below. If any of the characters are printable ASCII characters, then print those, too. If none is, you may omit the ASCII column header.    

Chapter 22 Solutions

C++ How to Program (10th Edition)

Knowledge Booster
Background pattern image
Computer Science
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License