Skip to main content
Logo image

Dive Into Systems: Exercises

Section 4.3 Converting Between Bases

Exercise 4.3.1. Byte Prefixes.

Exercise 4.3.2. Hex to Binary Conversion.

Given a hexadecimal digit, how many binary bits will you need to store an equivalent amount of information (for any possible hexadecimal digit)?

Exercise 4.3.3. Binary to Hex Conversion.

    Assume that when converting from binary to hexadecimal, you accidentally started grouping bits from left to right instead of from right to left. For which of the following numbers will this cause a problem? (Select ALL the apply.)
  • 0b11011111
  • Incorrect.
  • 0b110110100000
  • Incorrect.
  • 0b11011
  • Correct!
  • 0b00111
  • Correct!
  • 0b101111
  • Correct!
Hint.
Think about what happens after you group the bits together.

Exercise 4.3.4. Binary to Hex Conversion.

Convert the following binary number to its equivalent hexadecimal representation: 0b10110110011
Hint.
Some padding is needed.

Exercise 4.3.5. Decimal to Hex Conversion.

    True or False: You can convert from decimal to hexadecimal by first converting from decimal to binary and then converting from binary to hexadecimal representation.
  • True
  • Correct!
  • False
  • Incorrect.

Exercise 4.3.6. Decimal to Binary.

In computer networking, an IPv4 address is a 32-bit number that uniquely identifies a device in a network. An IPv4 address is typically written in dotted-decimal format as four decimal numbers separated by periods, each decimal number representing an 8-bit field of the address: dd.dd.dd.dd
Here are two example IPv4 addresses:
0.0.0.0
129.144.50.56
What’s the binary form of IPv4 address 192.0.2.130? A partial answer is given below: .00000000.00000010.
Hint.
See Section 4.2.3. The powers-of-two approach may be easier for a small value in the range of 0~255.

Exercise 4.3.7. Binary to Decimal.

Unix represents file access permissions in three sets of bits, three bits in each set. The three sets represent permissions for the file owner (the leftmost set), the group the file owner is in (the middle set), and others. The three bits in each set represent read (r), write (w), and execution (x) permissions respectively: rwx rwx rwx
For example, permissions 110100000 (equivalent to 110 100 000) indicate read+write permissions for the file owner, read-only to users in the same group as the file owner, and no access to anyone else.
These permissions in decimal are 640 (equivalent to 6 4 0).
To grant full access (read, write and execute) to the owner of a file, read and execute to the group, and red-only access to anyone else:
What binary representation should be used? Enter without spaces.
What equivalent decimal representation should be used?
Hint.
Express the permissions in binary first and then convert each three-bit group to an octal digit (or a decimal digit in the range 0~7).