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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:33:49+00:00 2026-05-26T13:33:49+00:00

I know I can use bitconverter.GetBytes to get the bytes from an integer. However,

  • 0

I know I can use bitconverter.GetBytes to get the bytes from an integer.
However, I need an array where the contents can be compared for sort order.

e.g.

var plusOne = BitConverter.GetBytes(1);
yields bytes: 0,0,0,1

var plusOne = BitConverter.GetBytes(2);
yields bytes: 0,0,0,2

So far so good:

but:

var minusOne = BitConverter.GetBytes(-1);
yields bytes: 255,255,255,255

Nothing strange here.
But comparing the minusOne byte array with the plusOne bytearray would say that the minusOne byte array is greater than the plusOne (255 > 0)

Is there any fancy way to shift, xor etc, so that Int.Min would give 0,0,0,0 and int.Max would give 255,255,255,255 ??

Sorry for the confusion 🙂

  • 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-05-26T13:33:50+00:00Added an answer on May 26, 2026 at 1:33 pm

    Simply add int.MaxValue + 1 to the current value casted to an uint to preserve the range like:

    var result = BitConverter.GetBytes((uint)((long)input - int.MinValue));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can use something like User.sort {|a, b| a.attribute <=> b.attribute} or
I know I can use the RODBC library for accessing excel (.xls) docs from
I know I can use activate_plugin() from inside a given, active plugin in WordPress,
I know I can use a quasi-random number generation function/variable called Rnd. However, I've
I know you can use sed to get the nth line of a text
I know you can use a combination of GetLogicalDrives() and GetDiskFreeSpaceEx() to get the
I know we can use the charAt() method in Java get an individual character
I know you can use :contains to get elements who's innerHTML contains a certain
I know I can use PSMultiValueSpecifier to let user to choose a value from
I know you can use C++ keyword 'explicit' for constructors of classes to prevent

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.