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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:27:56+00:00 2026-06-18T04:27:56+00:00

In C# var buffer = new byte[] {71, 20, 0, 0, 9, 0, 0,

  • 0

In C#

var buffer = new byte[] {71, 20, 0, 0, 9, 0, 0, 0};

var g = (ulong) ((uint) (buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24) |
                    (long) (buffer[4] | buffer[5] << 8 | buffer[6] << 16 | buffer[7] << 24) << 32);

In C++

#define byte unsigned char
#define uint unsigned int
#define ulong unsigned long long

byte buffer[8] = {71, 20, 0, 0, 9, 0, 0, 0};

ulong g = (ulong) ((uint) (buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24) |
                    (long) (buffer[4] | buffer[5] << 8 | buffer[6] << 16 | buffer[7] << 24) << 32);

C# outputs 38654710855, C++ outputs 5199.

Why? I have been scratching my head on this for hours…

Edit: C# has the correct output.

Thanks for the help everyone 🙂 Jack Aidley’s answer was the first so I will mark that as the accepted answer. The other answers were also correct, but I can’t accept multiple answers :\

  • 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-18T04:27:57+00:00Added an answer on June 18, 2026 at 4:27 am

    The C++ is not working because you’re casting to long which is typically 32-bits in most current C++ implementation but whose exact length is left to the implementor. You want long long.

    Also, please read Bikeshedder’s more complete answer below. He’s quite correct that fixed size typedefs are a more reliable way of doing this.

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

Sidebar

Related Questions

I have this code: public byte[] SerializeToBlob() { using (var buffer = new MemoryStream())
private static Int64 NextInt64(Random rnd) { var buffer = new byte[sizeof(Int64)]; rnd.NextBytes(buffer); return BitConverter.ToInt64(buffer,
var guidComPorts = Guid.Empty; UInt32 dwSize; IntPtr hDeviceInfo; var buffer = new byte[512]; var
var buffer = new byte[short.MaxValue]; var splitString = new string[] {\r\n}; while (_tcpClient.Connected) {
I read the input buffer from a console application (CMD) like this: var pBuffer
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
I got this (i also tried crStream.CopyTo(ms)): var cryptic = new DESCryptoServiceProvider(); cryptic.Key =
When using a blocking TCP socket, I don't have to specify a buffer size.
I need help converting this code from C# to Java. public static ulong GetChecksum(byte[]
I have a two very simple methods to encrypt/decrypt a byte[] using the AesCryptoServiceProvider.

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.