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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:51:00+00:00 2026-06-16T21:51:00+00:00

Using .NET 4.0 Using dotPeek .NET decompiler A little bit confused with code of

  • 0

Using .NET 4.0
Using dotPeek .NET decompiler

A little bit confused with code of System.BitConverter.ToInt32():

public static unsafe int ToInt32(byte[] value, int startIndex)
    {
      if (value == null)
        ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
      if ((long) (uint) startIndex >= (long) value.Length)
        ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
      if (startIndex > value.Length - 4)
        ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
      fixed (byte* numPtr = &value[startIndex])
      {
        if (startIndex % 4 == 0)
          return *(int*) numPtr;
        if (BitConverter.IsLittleEndian)
          return (int) *numPtr | (int) numPtr[1] << 8 | (int) numPtr[2] << 16 | (int) numPtr[3] << 24;
        else
          return (int) *numPtr << 24 | (int) numPtr[1] << 16 | (int) numPtr[2] << 8 | (int) numPtr[3];
      }
    }

How to understand this part of code?:

if (startIndex % 4 == 0)
  return *(int*) numPtr;

I mean why start position in byte array matters?

  • 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-16T21:51:01+00:00Added an answer on June 16, 2026 at 9:51 pm

    numPtr points to the location in the byte array where the 32-bit value is stored.

    In the event that this address is 4-byte aligned, it can simply be read directly through a cast to an integer: the byte pointer is converted to an integer pointer and then this is deferenced.

    Otherwise, each byte must be read individually and then added together to make a 32-bit integer. This is because most CPUs can only read 4-byte values directly if they are 4-byte aligned.

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

Sidebar

Related Questions

I am using .NET console application to gather performance data of the system. For
Using .NET's System.Drawing.Graphics GDI stuff, I have a shape consting of two arrays of
Using .Net 4.0. I have a some code which tries to open a connection
Using .NET 2.0. System.Drawing is in my References list. Here is my using statement:
using .NET Clipboard API you can write following code: //dataObject - instance of IDataObject,
Using net-snmp, table code generated by mib2c -c mib2c.iterate.conf fooBarTable and then heavily hacked.
Iam using .NET 3.5. I have asp.net mvc app. There is base controller: public
Using .Net 4.0 The line of code to create the PrincipalContext is: PrincipalContext context
Using .Net 4, isn't it possible to include forward slash in route parameters or
Using .net 2.0 . I want to display a column in a DataGridView as

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.