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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:27:39+00:00 2026-06-09T04:27:39+00:00

Are there any advantages from doing conversion like this int i = 1024; byte

  • 0

Are there any advantages from doing conversion like this

int i = 1024;
byte b = (byte)i;

over doing this

int i = 1024;
byte b = *((byte*) &i);

I mean, if you want to use the second method you must use unsafe code, that means that the JIT can’t optimize it as it wishs (I think it’s doing internally the second way) and so on.

Can somebody explain me when and why to use the first / the second method?

Greetings

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

    Those two are not equivalent.

    The first is a simple language defined cast. Its result is well defined: The first one returns the 8 least significant bits.

    The second is effectively a reinterpret-cast. It returns the first 8 bits in memory. Which happen to be the same on typical little-endian systems, but differ on big-endian systems.

    There are a few rare instances where reinterpret-casts are useful, but this isn’t one of them. You should always use normal casts, unless you have a problem that can only be solved with reinterpret casts.

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

Sidebar

Related Questions

Are there any advantages of using one over the other besides readability?
Are there any advantages of Loaders over Async task? Also, how to make loaders
I just wonder - are there any advantages to installing perl modules from the
I am wondering if there are any advantages of using any of these over
Are there any advantages or disadvantages to using multiple assignment in a statement? In
Are there any inherent advantages or disadvantages when it comes to handling DDoS attacks
Is there any advantage of using int vs varbinary for storing bit masks in
When designing a client/server architecture, is there any advantage to multiplexing multiple connections from
Is there any advantage in doing bitwise operations on word boundaries? Any CPU or
From this post How to use ROW_NUMBER in the following procedure? There are two

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.