Giter Club home page Giter Club logo

cpp_02's Introduction

Fixed-Point Conversion

Fixed-Point numbers are a convenient way to represent fractional numbers using a fixed number of bits. In fixed-point representation, the binary point is analogous to the decimal point in base-ten numbers but positioned differently in binary.

The Binary Point

The Binary Point represents the boundary between the whole number and fractional parts of the fixed-point number. Although there's no distinct symbol for the Binary Point in binary representation, we conceptually place it at a fixed location within the number. For instance, in a 32-bit number, we can assume the Binary Point is between bits 15 and 16, with 16 bits dedicated to the whole number part and 16 bits to the fractional part. The most significant bit in the whole number field is often reserved for the sign, leaving 15 bits for the magnitude.

Place Value Method

Not all numbers can be exactly represented in fixed-point form, so we use the closest approximation. The place value method allows us to determine the value of a fixed-point number.

For example, consider the following fixed-point representation:

32 + 8 + 2 + 1 + 0.25 + 0.03125 + 0.0078125 + 0.00390625 = 43.2869375

Repeated Multiplication

To convert a decimal fraction to a binary fraction in fixed-point form, you can use the repeated multiplication technique. Here's a simple procedure:

  1. Multiply the fractional part of the number by 2.
  2. Take the integer part of the result (either 1 or 0) as the next bit.
  3. Repeat this process until you obtain the desired number of bits to the right of the binary point.

For instance, to convert the decimal fraction 0.3568 into a fixed-point binary representation with 8 bits to the right of the binary point:

0.3568 is approximately equal to 0.01011011 in fixed-point binary.

This process continues until you have the required number of bits to represent the fraction.

Example: Conversion from Float to Fixed-Point

Let's consider an example where we convert a floating-point number to a fixed-point number.

Step 1: Start with a Floating-Point Number

Suppose we have the floating-point number 5.75.

Step 2: Convert to Binary

First, convert the whole part (5) and the fractional part (0.75) to binary:

  • The whole part (5) in binary is 101.
  • The fractional part (0.75) in binary is 0.11.

Step 3: Combine Binary Parts

Combine the binary whole part and fractional part:

  • 5.75 in binary is 101.11.

Step 4: Fixed-Point Conversion

Now, assume we want to represent this number in a fixed-point format with 4 bits to the right of the binary point:

  • The whole part is 101, and the fractional part is 11. To represent it in fixed-point form with 4 bits for the fractional part, we might need to truncate or round.

  • The fixed-point representation with 4 bits to the right of the binary point is 101.1100.

cpp_02's People

Contributors

emohamedd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.