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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:20:23+00:00 2026-06-06T13:20:23+00:00

I guess my main question is, will this always work as long as I

  • 0

I guess my main question is, will this always work as long as I don’t re-initialize (new byte[#]) the array that was passed as the parameter?

static unsafe decimal GetDecimal(byte[] ba)
{
    decimal* decimal_PTR;
    fixed (byte* byte_PTR = &ba[0])
    {
        decimal_PTR = ((decimal*)byte_PTR);
    }
    return *decimal_PTR;
}

I’m not sure how C# handles arrays in memory. I didn’t even know they were managed types until about an hour ago. I just want to know if I pass in a decimal as a byte[], will it always return the correct value? Any other information you can provide is appreciated.

  • 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-06T13:20:24+00:00Added an answer on June 6, 2026 at 1:20 pm

    After @MJLaukala’s clarification through comments:

    1. An Array in .Net is a block of contiguous memory just like any other language. But unlike C/C++ this block not only stores the array’s elements but also other ‘information’ including rank and length of the array. Having said this, &ba[0] will return the pointer to the first element of the array and you can safely increment the pointer to go till the last element. ba.Length will provide the number of elements in the array.

    2. Now if you are sure that the byte array represents the decimal exactly then your code will work fine.

    Memory layout of decimal (128 bits):

    First 2 bytes are 0

    3rd byte contain a value between 0 and 28, indicating the power of 10 to divide the 96-bit integer part by to produce the Decimal value

    4th byte : first 7 bits are zero, 8th bit indicates the sign of the decimal (1 meaning negative)

    Next 12 bytes: Integer part of the Decimal.

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

Sidebar

Related Questions

Here's the main question I guess : Is there a .NET way to get
I'm not 100% sure that this is an appropriate question for SO but here
Has anyone done something like this? How? I'm just starting a project that will
I'm still kind of new to the erlang/otp world, so I guess this is
I'm not sure to which area this question is related , but I will
This question comes from this one: c++ pass array to function question but since
I guess this question was asked in one way or another, but I'm looking
I am writing some code in C: int main(){ char guess[15]; guess = helloValidation(*guess);
Guess that I have a TextView that I want to update it in some
I guess that the difficult part is the source. Do you know any webpage

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.