Java Variables and Data Types

Recap: Floating Point Conversion

As we advance, understanding the conversion between binary and decimal floating point numbers is crucial. This topic has been previously explored in the course:

Computer Science Fundamentals → Data Storage & Number System → Floating Point Number

If possible, we recommend watching the video to gain a comprehensive understanding of the concept. However, for those who prefer reading or need a quick refresher, a written recap of the video is also available.
Decimal system, which employs digits 0 through 9, totaling 10 different symbols—hence, it's known as base 10. In this system, each digit's position holds a specific value, exemplified by units (), tens (), hundreds (), and so on. The key here is understanding the exponential growth or decline in value as we move through each position, especially past the decimal point, where values decrease, dividing by 10 each time.
Unlike the decimal system's decimal point, other number systems refer to this as the radix point—a universal term across number systems.
Focusing on the Binary System, its base is 2, meaning the place values follow powers of 2, with negative powers after the radix point (e.g., , ).

Converting Binary to Decimal

Consider the binary floating-point number "101.101". To convert this to its decimal equivalent, we examine each digit's place value:
Left of the Radix Point (Whole Number Part)
The rightmost '1' represents (1).
The '0' contributes nothing since it represents (2), but 0 times anything is 0.
The leftmost '1' represents (4).
Combining these, we have 4 + 0 + 1 = 5.
Right of the Radix Point (Fractional Part)
The rightmost '1' represents (1/8 or 0.125).
The '0' adds nothing as it represents .
The leftmost '1' represents (1/2 or 0.5).
Adding these gives 0.5 + 0 + 0.125 = 0.625.
Thus, the decimal equivalent of "101.101" is 5.625.

Converting Decimal to Binary

Converting "5.625" to binary is slightly more complex, involving separate processes for the integer and fractional parts.
Integer Part Conversion
Divide 5 by 2 repeatedly, tracking remainders, until the quotient is 0. This gives us the binary equivalent of 5 as "101".
Fractional Part Conversion
Multiply the fractional part (0.625) by 2, tracking the integer part of the result. Repeat this process until the fractional part becomes 0 or reaches a repeating cycle. For 0.625, we get "101" as the binary representation of the fractional part.
Combining these, "5.625" in binary is "101.101".
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.