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

  • Home
  • SEARCH
  • 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 8550365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:56:02+00:00 2026-06-11T13:56:02+00:00

Earlier I came up with something, which I solved, but it got me later

  • 0

Earlier I came up with something, which I solved, but it got me later
let’s take a look at a similar example of what I was on:

int b = 35000000; //35million
int a = 30000000;
unsigned long n = ( 100 * a ) / b;

Output: 4294967260

I simply changed a to unsigned long and the correct 85% output would come up, because a is a signed 32bit integer. But this got me later. There is no value assignment to a during ( 100 * a ) there is just simply a calculation and the correct value which is 3billion should come up instead of an overflow. To understand if there wasn’t really an assignment to a I removed a from the code and manually write the value instead instead:

int b = 35000000;
unsigned long n = ( 100 * 30000000 ) / b;

The big surprise was that the output is also: 4294967260
And of course value of 3billion can be assigned to an unsigned long.
My first thought was that ( 100 * 30000000 ) was causing an overflow, but then I asked “an overflow on what? there is nothing to be overflowed”.
Then I changed b to unsigned long, which even most suprisingly the output was correct 85%.

In the first example changing a to unsigned long

int b = 35000000;
unsigned long a = 30000000;
unsigned long n = ( 100 * a ) / b;

and leaving bas an int as it is works, but on the second example it doesn’t, what is occuring?

This might be a little overwhelming to let me re-write all examples with the ones who work and the ones who dont.

Works (Output = 85):

int b = 35000000;
unsigned long a = 30000000;
unsigned long n = ( 100 * a ) / b;

Works (Output = 85):

unsigned long b= 35000000;
unsigned long n = ( 100 * 30000000 ) / b;

Doesn’t works (Overflow):

int b = 35000000;
int a = 30000000;
unsigned long n = ( 100 * a ) / b;

Doesn’t works (Overflow):

int b = 35000000;
unsigned long n = ( 100 * 30000000 ) / b;
  • 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-11T13:56:03+00:00Added an answer on June 11, 2026 at 1:56 pm

    Let me explain what is occuring here.
    On:

    int b= 35000000;
    unsigned long n = ( 100 * 30000000 ) / b;
    

    The value is incorrect because overflow happens at ( 100 * 30000000 )
    But on:

    unsigned long b= 35000000;
    unsigned long n = ( 100 * 30000000 ) / b;
    

    The value is correct, so what is happening?

    In the first example b is a int, as said by Tony, an overflow happens because the register where the temporary value of ( 100 * 30000000 )will be assigned is able to hold 32bit signed integers, that happens because 100 is an int and 30000000 is also an int AND because b is also an int, the register in this case are smart, when ALL values on the right side are int it assumes the values also have to be an int but when a mighty unsigned long comes to the party, it knows that dividing an int by an unsigned long, / b is wrong, so it stores the value of ( 100 * 30000000 ) to an unsigned long.

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

Sidebar

Related Questions

Earlier this week, I had to do something which feels like a semantics violation.
Earlier today I asked similar problem to find the maximum element which is common
Earlier today I came across Kaazing's WebSocket API for HTML5. Looks fantastic, but as
I asked a similar question earlier and we came down to this CSS solution
I was reading over how to 'Create a JavaScript Library' earlier and I came
I came across a strange behaviour with Chrome earlier that I can't seem to
Earlier today I was working on a PHP 5.3+ application, which meant I was
I've been reading up on this whole subject, but I never came across this
I came across a few articles like this one , which suggest that some
I was refactoring some code earlier and I came across an implementation of an

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.