I practiced converting between binary, decimal, and hexadecimal using bc, printf, and Python, the math that underpins subnetting, file permissions, and byte-level analysis. Fluency in base conversion makes CIDR masks and octal modes intuitive rather than memorized.

Objective & Context

Networking and permissions are base-2 and base-8 at heart. This lab builds quick conversion skills so subnet masks, chmod octals, and hex dumps read naturally, directly supporting the subnetting and permissions labs.

Environment & Prerequisites

  • Linux shell with bc, printf, and python3.
  • Sample values: IP octets, permission bits, byte values.

Step-by-Step Execution

1. Decimal to binary with bc

echo "obase=2; 192" | bc

2. Decimal to hex with printf

printf '%X\n' 255

3. Hex to decimal in Python

python3 -c "print(int('FF',16))"
11000000
FF
255

Validation & Testing

Convert an IP octet (192) to binary and a permission value (755) reasoning, then verify round-trips back to decimal. Pass criteria: conversions agree across bc, printf, and Python and match manual calculation.

Advanced: Troubleshooting
  • bc base confusion: set ibase before the value and obase for output; order matters.
  • Wrong hex case: use %x for lowercase, %X for uppercase in printf.
  • Leading zeros lost: pad with printf width specifiers when needed.

Key Results

  • Converted fluently across base-2, base-10, and base-16.
  • Applied binary math directly to subnet mask reasoning.
  • Verified conversions round-trip across 3 independent tools.
  • Made octal permission values intuitive rather than memorized.