Monday, 20 June 2022

Chapter 25 // Drill 3, 4, 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 25 // Drill 3

Using hexadecimal literals, define short unsigned ints with:
  • Every bit set
  • The lowest (least significant bit) set
  • The highest (most significant bit) set
  • The lowest byte set
  • The highest byte set
  • Every second bit set (and the lowest bit 1)
  • Every second bit set (and the lowest bit 0)

Chapter 25 // Drill 4

Print each as a decimal and as a hexadecimal.

Chapter 25 // Drill 5

Do 3 and 4 using bit manipulation operations (|, &, <<) and (only) the literals 1 and 0.


I cheated with drill 3 and just wrote out the binary then converted it to hex using 

5 was annoying because you can directly type out binary literals in C++14 and assign them to things. The challenge came from only using 1 and 0. Like setting the highest byte can be done with 1 << 15 but 15 isn't 1 or 0.

I honestly had no idea how to do the last 2 using only 1 and 0, so I cheated and just used direct binary strings.


No comments:

Post a Comment