Ads

NC ASSIGNMENT

 NC ASSIGNMENT 1

Note: Sirf code ka print lgna ya ss baqi puri assignment handwritten hai

Q1. Scenario Setup:

Assume you are developing a cloud storage system that tracks file sizes and user storage limits.

• A user uploads a file of 1,073,741,824 bytes (exactly 1 GB in binary format).

• The system converts this to gigabytes using both binary (230 bytes = 1 GB) and decimal

(109 bytes = 1 GB) conversions.

• The displayed value is rounded to two decimal places.

Answer:

·       Binary Conversion

·       Decimal Conversion

·       Final Display

·       Binary (Base 2): 1.00 GB

·       Decimal (Base 10): 1.07 GB




2. Tasks for the Students:

a. Write a program (in Python/Java/Matlab) to:

• Convert the file size (1,073,741,824 bytes) to GB using both binary (230) and decimal

(109) conversions.

• Display the rounded values to two decimal places.


Answer:

file_size_bytes = 1_073_741_824 

binary_gb = file_size_bytes / (2 ** 30)

decimal_gb = file_size_bytes / (10 ** 9)

print(f"Binary Conversion: {binary_gb:.2f} GB")

print(f"Decimal Conversion: {decimal_gb:.2f} GB")


b. Investigate precision errors:

• Convert the displayed GB value back to bytes and compare it with the original file size.

• Analyze whether discrepancies occur due to floating-point representation.

Answer:

Step 1: Convert GB Back to Bytes

Binary GB to Bytes (1.00 GB)

1.00  * 230= 1.00 *1,073,741,824 = 1,073,741,824 bytes

Decimal GB to Bytes (1.07 GB)

1.07 *109 = 1.07 *1,000,000,000 = 1,070,000,000 bytes

Difference:


1,073,741,824 - 1,070,000,000 = 3741824 bytes  3.47MB

Step 2: Investigate precision errors:

The binary conversion is exact because 1 GB (binary) = 2³⁰ bytes, which was the original file size.

The decimal conversion introduces a precision error because:

1.07 GB is a rounded value.

Converting 1.07 back to bytes loses accuracy due to floating-point rounding.

The error of 3.57 MB (≈ 0.33%) is due to this conversion.


c. Experiment with different file sizes (e.g., 500 MB, 5 GB) and observe if the error becomes

more noticeable.

Answer:




Conclusion:

  • Binary (Base 2) conversions remain precise because they align perfectly with memory allocations based on powers of 2.
  • Decimal (Base 10) conversions introduce rounding errors as values don’t map exactly to powers of 2.
  • The larger the file size, the more noticeable the discrepancy in decimal conversions due to floating-point precision and rounding errors.


Reflection Questions:

1. What caused the difference between the original and reconverted file sizes?
Answer:

The differences arise due to:

  • Binary vs. Decimal Conversion: Binary GB is based on powers of 2, while decimal GB (GB) is based on powers of 10. 
  • Floating-Point Precision: Some decimal values cannot be represented exactly in binary, leading to minor precision losses when converting back and forth.
  • Rounding during Display: When displaying file sizes with limited decimal places (e.g., 2 decimal places), small truncations or approximations can cause discrepancies.
2. How can such errors be mitigated in cloud storage systems?
Answer:

To minimize these errors, cloud storage systems can:

  • Use Integer-Based Storage Accounting: Instead of floating-point operations, use integers (bytes) directly for calculations to avoid precision errors.
  • Round Only at Display Time: Keep precise values internally and round them only when presenting them to users, reducing cumulative rounding errors.
  • Metadata Tracking: Store both the raw byte count and formatted display size separately to avoid unnecessary conversions
3. Why is it important to carefully handle floating-point precision in computing, especially
in storage and networking?

Answer:

  • Avoiding Data Loss: Precision errors can lead to unintended data loss or miscalculations in available vs. used storage.
  • Billing Accuracy: Cloud storage providers charge based on used storage, and even small rounding errors can lead to incorrect billing.
  • Networking & Bandwidth Calculation: In networking, precise data size calculations impact transmission rates, buffering, and latency.
  • Security Concerns: In some cases, precision errors can be exploited in attacks (e.g., floating-point rounding vulnerabilities in financial transactions).
  • Post a Comment

    0 Comments