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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:15:59+00:00 2026-06-02T13:15:59+00:00

The following code in C# gives result 228452386 UInt32 a; int k = 0;

  • 0

The following code in C# gives result “228452386”

UInt32 a;

int k = 0;

a = 0x9E3779B9;

a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24));

After above code is ran, “a” contains “228452386”.

But the following same code in VB.NET results in “Arithmetic operation resulted in an overflow”. Basically the last statement is returning value “1868983913”, so the runtime error is generated.

Dim a As UInt32

Dim k As Integer = 0

a = &H9E3779B9UI

a += CUInt(AscW(url(k + 0)) + (AscW(url(k + 1)) << 8) + (AscW(url(k + 2)) << 16) + (AscW(url(k + 3)) << 24))

Please note the variable “url” in the above code could be any string and it is same for both codes.

When I run the following statements in both C# and VB.NET than they both return same value

C#

(UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24))

VB.NET

CUInt(AscW(url(k + 0)) + (AscW(url(k + 1)) << 8) + (AscW(url(k + 2)) << 16) + (AscW(url(k + 3)) << 24))

Both statements return the value “1868983913” for “url” “info:microsoft.com”. But when I run the complete statement with a += ……… then VB.NET gives an error while C# returns the value “228452386”.

  • 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-02T13:16:01+00:00Added an answer on June 2, 2026 at 1:16 pm

    You have an overflow, because the result of adding the two numbers you’re adding are larger than what fits in an UInt.

    The resulting number is a 33 bit number, UInts fit only 32 bits.

    • In C#, the most significant bit is just chopped of, keeping the 32 bits that fit inside the UInt. (This new value is not the actual result of adding your numbers.)
    • In VB.NET you get an exception stating that the number doesn’t fit.

    The VB.NET compiler (or VS) allows you to turn of this overflow checking, so that VB.NET will behave like C# in this case.

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

Sidebar

Related Questions

The following code executes as expected but gives a NullPointerException at the end. What
The following code executes fine in Firefox and Chrome, but gives an error: 'null'
Can I confirm that the following C code gives undefined result for b: unsigned
The following code gives me an error. import easygui result = easygui.enterbox(message=Enter your name,
I have the following php code that gives me an unexpected result: $foo =
I'm having problems the following code gives me no results. however if I uncomment
Given the following code: var a = 'somegarbage=http://somesite.com/foo/bar/&moregarbage'; var result = a.match(/http.+\//g); Produces the
The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression
when i am analyze my project following code gives me leakage warning. is there
The following C++ code gives an error while compiling: #include<iostream> using namespace std; class

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.