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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:06:23+00:00 2026-06-01T00:06:23+00:00

consider the following code : ushort a = 60000; a = (ushort)(a * a

  • 0

consider the following code :

ushort a = 60000;
a = (ushort)(a * a / a);
Console.WriteLine("A = " + a);  

//This prints 53954. Why??

and

ushort a = 40000;
a = (ushort)(a * a / a);
Console.WriteLine("a = " + a.ToString());

//This prints 40000. how??

any help appreciable …

  • 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-01T00:06:24+00:00Added an answer on June 1, 2026 at 12:06 am

    Because 60000^2 is 3600000000 but the biggest number an int can hold is 2,147,483,647, so it starts over from -2,147,483,648.

    A ushort can hold 65,535 and then starts over from 0:

    For instance, this prints 0:

    ushort myShort = 65535;
    myShort++;
    Console.WriteLine(myShort); //0
    

    It’s easier to see this if you break it into steps:

    var B = A * A;
    

    That actually exceeds the capacity of an int32, so it starts from -2,147,483,648 thus b equals -694967296
    Then when you split B/A you get: -11582 which, when cast into a ushort becomes 53954.

    ushort A = 60000;
    var B = A * A; //-694967296
    var C = B / A; //-11582
    ushort D = (ushort)(C); //53954
    

    The reason that 40000 works is that it does not exceed the capacity of an int32.

    ushort A = 40000;
    var B = A * A; //1600000000
    var C = B / A; //40000
    ushort D = (ushort)(C); //40000
    

    uint can hold 60000^2 though, so this works:

    ushort A = 60000;
    var B = (uint)A * A; //3600000000
    var C = B / A; //60000
    ushort D = (ushort)(C); //60000
    

    The reason that casting C to ushort yeilds 53954 is because the bytes of C is:

    96
    234
    0
    0
    

    And the bytes of D is:

    96
    234
    

    So they hold the same backing bytes, that’s why you get 53954 and -11582

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

Sidebar

Related Questions

Consider the following code block: using (PlayersDataContext context = new PlayersDataContext()) { Console.WriteLine(context.Players.Count()); //
Consider the following code (you can just put this in the developer console in
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
Consider the following code example: TempList.ForEach(Function(obj) obj.Deleted = True End Function) And this one:
Consider the following code: function Robot(weapon) { this.weapon = weapon; this.fire = function() {
Consider the following code: $(document).click(function (event) { console.log(Ok); }); $(document).add($('p')).click(function onceHandler(event) { console.log('Clicked.'); });
Consider the following code: $('div').click(function(){ $(this).animate({height:100}, 500) $(this).css({opacity:1}); }); Versus: $('div').click(function(){ $(this).animate({height:100}, 500); })
This is rather interesting, I think. Consider following code, both the window.onload and body
Consider the following code: private static void WriteProcesses(StreamWriter sw, DateTime d) { sw.WriteLine(List of
Consider the following code // BOGP.cpp : Defines the entry point for the console

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.