Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:07:13+00:00 2026-06-14T19:07:13+00:00

I need insight on signed conversion. An input to a C routine is guaranteed

  • 0

I need insight on signed conversion.

An input to a C routine is guaranteed to lie in the range -Pi to pi. This is passed by “double” data type.

Since my device lacks a FPU, I must perform math (Divide input by Pi )on the input using fixed point on a 24bit register.

Since the range is known, I am able to store the input data in Q3.10 format.

So:

 typedef int Q3_10;
 Q1_10 ReciProc_Pi = 0x145;
 Q3_10 FP_DataQ310 = (Q3_10)(Input_Data * 1024); /* Scale by 2^10 */
 Q4_20 FP_DataQ420 = FP_DataQ310 * ReciProc_Pi;  /* Input / Pi */
 Q4_23 FP_DataQ423 = FP_DataQ420 << 3; /* Change 4Q20 to 4Q23 */
 Q1_23 FP_DataQ123 = FP_DataQ423 & 0xFFFFFF; /* Retain 24 bits */

I am able to verify printing out fraction using the venerable printf.

 double Fraction = (double)((double)FP_DataQ123 / (65536 * 128));
 printf("Fraction = %f\n", Fraction);

So for an input such as 2.5678, the fraction is correctly identified as 0.81483.

Are negative numbers to be treated the same?

Computation above fails when I pass -1.757. The printf reports a positive fraction 1.442410.
But the hexadecimal value of FP_DataQ123 seems allright (0xB8a0e8). The sign bit is correctly set to 1.

I later did this:

 Q1_23 FP_DataQ123 = FP_DataQ423 & 0xFFFFFF; /* Retain 24 bits */
 if (FP_DataQ123 >> 23)
  {
    printf("Input is negative\n");
    FP_DataQ123 = (~FP_DataQ123) & 0x7FFFFF; /* Complement */ 
    double Fraction = (double)((double)FP_DataQ123 / (65536 * 128));
    printf("Fraction = %f\n", Fraction);
  }

The printf now reports correct fraction 0.557, but without the minus sign.

How do I get printf to print -0.557 without complementing FP_DataQ123?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:07:14+00:00Added an answer on June 14, 2026 at 7:07 pm

    So it turns out that all of the integer bits had to be sign extended.

    Q1_23 FP_DataQ123 = FP_DataQ423 & 0xFFFFFF; /* Retain 24 bits */
    

    Although this is correct because Bit-24 is a 1 indicating negative 1Q23 fraction, printf needed everything after Bit-23 to be sign extended.

    Q1_23 FP_DataQ123 = FP_DataQ423 ; 
    

    does the trick.
    This need for sign extension is fair enough because we are asking it to print a 64bit number and not a 24bit number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
Need some insight on how this works I have the following piece of code
All - Need some insight into this issue. I have created a sample project
I am pretty much stuck on this and need some insight. When the user
So in order to get the insight data for my application I need the
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need just a push in the right direction with this. I'm building a multi-language
guys need some insight here. I know the definition of a protocol, being new
I need a little insight into some authentication issues in adobe AIR. Three related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.