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 1098121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:31:57+00:00 2026-05-17T00:31:57+00:00

The ISO C standard allows three encoding methods for signed integers: two’s complement, one’s

  • 0

The ISO C standard allows three encoding methods for signed integers: two’s complement, one’s complement and sign/magnitude.

What’s an efficient or good way to detect the encoding at runtime (or some other time if there’s a better solution)? I want to know this so I can optimise a bignum library for the different possibilities.

I plan on calculating this and storing it in a variable each time the program runs so it doesn’t have to be blindingly fast – I’m assuming the encoding won’t change during the program run 🙂

  • 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-05-17T00:31:58+00:00Added an answer on May 17, 2026 at 12:31 am

    You just have to check the low order bits of the constant -1 with something like -1 & 3. This evaluates to

    1. for sign and magnitude,
    2. for one’s complement and
    3. for two’s complement.

    This should even be possible to do in a preprocessor expression inside #if #else constructs.

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

Sidebar

Related Questions

The C standard states: ISO/IEC 9899:1999, 6.2.5.15 (p. 49) The three types char, signed
Is there an ISO standard address format? I can't seem to find one, and
I've written my own qr code generator. I followed both the ISO standard as
It is not clear from the PDF ISO standard document (PDF32000-2008) whether a comment
I've just spotted the following in the C99 ISO standard, 7.19.6.1 The fprintf function
The ISO C Standard (ISO/IEC 9899) and the ISO C++ Standard (ISO/IEC 14882) are
Is there any guarantee by any commonly followed standard (ISO C or C++, or
I have an XML document that has dates in standard ISO 8601 format. Like
Does anyone know the ISO standard that covers .NET 3.5? I found ISO/IEC 23270:2006,
Should every C++ programmer read the ISO standard to become professional?

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.