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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:26:44+00:00 2026-06-02T12:26:44+00:00

I’m writing up a QuadTree class and I need to include neighbor searches. I’m

  • 0

I’m writing up a QuadTree class and I need to include neighbor searches. I’m following along with this paper which includes a C implementation. (I’m basically converting it to C#.) And I’m having trouble because I’m not very good at working with binary numbers. I need to do the following things:

given #100 and #010, combine them to get #110. 1s will never overlap. right now what I do is store 100 and 10, when I add them it gives me 110.

perform left and right binary shifts on numbers like #011. right now I was storing 011 and applying the >> or << operator to it. This gives me completely the wrong number but strangely the logic I used it in to find common quad tree parents was working just fine.

given #011 and #001 sum them to get #100. Right now I’m storing 11 and 1, this obviously doesn’t work at all
.

Perform bitwise subtraction, same as above but – instead of + 🙂

perform ANDs, ORs and XORs.

So, right now I’m storing everything as an integer that looks like the binary value, and the math seems to be working for the ANDs, ORs, XORs and shifts. The numbers are crazy in the middle but I get the right answer in the end.

I’m trying an implementation right now where I store the integer value that is the value of the binary number but I have to convert back and forth a lot, this is particularly a pain because I’m converting between an integer representation of the Value of the number and a string representation of the binary number itself. Creating a new string every second line of code is going to be a performance nightmare.

Can you guys recommend a basic strategy for working with binary numbers in C#?

P.S. I don’t ever need to see the integer representation of these numbers. I really don’t care that #010 == 2, the work I need to do sees it as #010 end of story.

Hopefully this is more clear than my original post!

  • 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-02T12:26:48+00:00Added an answer on June 2, 2026 at 12:26 pm

    I hope this will clear up some confusion:

    • The literal 0x00000001 represents 1 using hexadecimal notation.
    • The literal 1 represents 1 using decimal notation.

    Here are some pairs of equivalent literals:

     0x9 ==  9
     0xA == 10
     0xF == 15
    0x10 == 16
    0x11 == 17
    0x1F == 31
    

    The primitive integral data types (byte, sbyte, ushort, short, char, uint, int, ulong, long) are are always stored in the computer’s memory in binary format. Here are the above values notated with five bits:

     1 == #00001
     9 == #01001
    10 == #01010
    15 == #01111
    16 == #10000
    17 == #10001
    31 == #11111
    

    Now, consider:

    unsigned int xLeftLocCode = xLocCode - 0x00000001;
    

    Either of the following is equivalent in C#:

    uint xLeftLocCode = xLocCode - 1;
    uint xLeftLocCode = xLocCode - 0x00000001;
    

    To assign the binary #10 to a uint variable, do this:

    uint binaryOneZero = 2;   //or 0x2
    

    Hexadecimal notation is useful for bit manipulation because there is a one-to-one correspondence between hexadecimal and binary digits. More accurately, there is a one-to-four correspondence, as each of the 16 hexadecimal digits represents one of the 16 possible states of four bits:

    0 ==  0 == 0000
    1 ==  1 == 0001
    2 ==  2 == 0010
    3 ==  3 == 0011
    4 ==  4 == 0100
    5 ==  5 == 0101
    6 ==  6 == 0110
    7 ==  7 == 0111
    8 ==  8 == 1000
    9 ==  9 == 1001
    A == 10 == 1010
    B == 11 == 1011
    C == 12 == 1100
    D == 13 == 1101
    E == 14 == 1110
    F == 15 == 1111
    

    It’s therefore fairly easy to know that 0x700FF, for example, has all the bits of the least significant byte set, none of the next most significant byte, and the lower three bits of the next most significant byte. It’s much harder to see that information at a glance if you use the literal 459007 to represent that value.

    In conclusion:

    Can you guys recommend a basic strategy for working with binary numbers in C#?

    Learn the table above, and use hexadecimal literals.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

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.