Skip to main content
Engineering LibreTexts

2.10 Exercises

  • Page ID
    83024
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    1. What are the following numbers in binary and hexadecimal?

    1.a \(13_{10}\)

    1.b \(15_{10}\)

    1.c \(25_{10}\)

    1.d \(157_{10}\)

    1.e \(325_{10}\)

    1.f \(1096_{10}\)

    2. What are the following numbers in decimal?

    2.a \(10011100_2\)

    2.b \(9 \rm C_{16}\)

    2.c \(1 \rm F_{16}\)

    2.d \(0 \rm C_{16}\)

    2.e \(109 \rm A_{16}\)

    3. Give the value of the following numbers in their hexadecimal representation (e.g., 232 = 0x4G)

    3.a \(2^{16}\)

    3.b \(2^{24}\)

    3.c \(2^{29}\)

    3.d \(2^{34}\)

    3.e \(2^{31}\)

    4. Give the 2’s complement form for each of the following numbers:

    4.a \(13\)

    4.b \(-13\)

    4.c \(156\)

    4.d \(-209\)

    5. Perform the following calculations using 2’s complement arithmetic. Show whether there is an overflow condition or not. CHECK YOUR AnswerS!

    5.a \(13 + 8\) with 5 bits precision

    5.b \(13 + 8\) with 6 bits precision

    5.c \(13 – 8\) with 5 bits precision

    5.d \(13 – 8\) with 6 bits precision

    5.e \(-13 – 8\) with 5 bits precision

    5.f \(-13 – 8\) with 6 bits precision

    5.g \(105 – 57\) with 8 bits precision

    6. Perform the following multiplication operations using binary shift operations. Check your answers.

    6.a \(5 * 4\)

    6.b \(13 * 12\)

    6.c \(7 * 10\)

    6.d \(15 * 5\)

    1. What is the hex representation of the following numbers (note that they are strings)?

    7.a “52”

    7.b “-127”

    8. Perform the following multiplication and division operations using only bit shifts.

    8.a \(12 * 4\)

    8.b \(8 * 16\)

    8.c \(12 * 10\)

    8.d \(7 * 15\)

    8.e \(12 / 8\)

    8.f \(64 / 16\)

    9. Explain the difference between a short circuiting and non short circuiting logical expression. Why do you think these both exist?

    10. In your own words, explain why the context of data found in a computer is important. What provides the context for data?

    11. Convert the following ASCII characters from upper case to lower case. Do not refer to the ASCII table.

    11.a 0x41 (character A)

    11.b 0x47 (character G)

    11.c 0x57 (character W)

    12 Convert the following ASCII characters from lower case to upper case. Do not refer to the ASCII table.

    12.a 0x62 (character b)

    12.b 0x69 (character i)

    12.c 0x6e (character n)

    13. Write the functions toUpper and toLower in the HLL of your choice (C/C++, Java, C#, etc.) The toUpper function converts the input parameter string so that all characters are uppercase. The toLower function converts the input parameter string so that all characters are lowercase. Note that the input parameter string to both functions can contain both upper and lower case letters, so you should not attempt to do this using addition.

    14. Implement a program in the HLL of your choice that converts an ASCII string of characters to an integer value. You must use the follow pseudocode algorithm:

         read numberString
           outputNumber = 0
           while (moreCharacters)          
               c = getNextCharacter
               num = c - '0';
               outputNumber = outputNumber * 10 + num;       
           print outputNumber;
    

    15. Write a program in the HLL of your choice to take a string representing a binary number, and write out the number in hex.

    16. Write a program in the HLL of your choice to take an integer, and write its value out in hex. You cannot use string formatting characters.

    17. Is bit shift by 1 bit the same as division by 2 for negative integer numbers? Why or why not?

    18. Can multiplication of two variables (not constants) be implemented using the bit shift operations covered in this chapter? Would you consider using the bit shift operations implementation of multiplication and division for two variables, or would you always use the mul or div operators in ARM assembly? Defend your choice.

    19. Should you use bit shift operations to implement multiplication or division by a constant in a HLL? What about assembly makes it more appropriate to use these operations?

    20. What does the Unix strings command do? How does the command attempt to provide a context to data? How might you use it?

    What you will learn (Chapter 3)

    In this chapter you will learn:

    1. an implementation of a template that that can be used to create the main function for an assembly language program using gcc
    2. how to write comments in ARM assembly for gcc
    3. the use of the ldr assembly instruction to load a memory address and a memory value into a register
    4. how to implement an assembly language program to print a “Hello World” message
    5. how to use the C printf and scanf functions in a program to input and output data
    6. value and reference variables
    7. the steps to build a program from shell, illustrating the compiling, linking and execution steps to create a program
    8. running a program from shell
    9. creating a makefile script to compile, link, and execute a program using the make command
    10. the use scanf and printf to input and output an integer value, illustrating the difference between a reference and a value
    11. learn what the gdbtui is, and how to use it to view a program execution.

    2.10 Exercises is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?