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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:57:33+00:00 2026-06-13T09:57:33+00:00

So it appears that the .NET performance counter type has an annoying problem: it

  • 0

So it appears that the .NET performance counter type has an annoying problem: it exposes long for the counter RawValue while the actual perf counter value in windows is unsigned and cannot be negative. For instance if you have a NumberOfItems64 counter The API will be perfectly happy to accept a negative value, then silently convert it to a very large number. In fact for half the value range of the counter the only way to set it there is to find the correct negative value to pass in!

I assume what is happening here is that they are taking the raw bits from the long and treating it as an unsigned 64-bit number. The negative values from two’s complement are just read as a straight up number for the counter.

So I’m trying to figure out how to coerce C# into just dropping the bits from the ulong straight into the long, since that’s what the API wants. But C# is being too helpful here… you can’t cast or use Convert.ToInt64(ulong) since it throws overflow exceptions because of the value being too large. I stumbled upon this way of doing the conversion:

Convert.ToInt64(myULong.ToString("X"), 16)

When it converts from a string in non-base 10 it assumes the number is in two’s complement and does what I need it to. But it’s not ideal because it needs to allocate an object and parse a string for every conversion and this API is going to be performance-critical. Is there a better way in C# to do this?

  • 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-13T09:57:34+00:00Added an answer on June 13, 2026 at 9:57 am

    A simple cast like

    ulong value1 = 0xFEDCBA9876543210UL;  // 18364758544493064720
    long value2 = (long)value1;           // -81985529216486896
    ulong value3 = (ulong)value2;         // 18364758544493064720
    

    preserves the bits in the value exactly.

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

Sidebar

Related Questions

It appears that calling Html.RenderAction in Asp.Net MVC2 apps can alter the mime type
It appears that in order to make TinyMCE work with an ASP.NET AJAX website,
I realized that appears this interface in .NET Framework 4.5 I was looking first
Is there an event that fires in vb.net just before a contextMenuStrip appears when
It appears that when I do git stash apply, I need to then type
I am looking into performance issues of a large C#/.NET 3.5 system that exhibits
It appears that when you access My.Settings.Default in VB.NET, your thread's CurrentPrincipal changes. Consider
It appears that .NET 3.5 is enforcing the SOAP 1.2 schema when dealing with
It appears that .NET's SmtpClient is creating emails with an extra dot in host
From some googling, it appears that .NET supports asynchronous operations with SQL Server 2005+.

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.