Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Nullio

binary number representation in c#

This topic is 5263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how do you represent a binary number in c#?? I know for a hex number is = 0xffffffff but what about binary?

Share this post


Link to post
Share on other sites
Advertisement
You can convert your number in binary notation to hexadecimal.

Each hex digit represents 4 binary digits. Or you can think
of it as every 2 hex digits is a byte, so that''s 8 binary digits.



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
If you need the binary representation just for interfacing with the user (reading/writing values to/from screen or file) you can use one of those fuctions to convert strings to numbers (or vice-versa), stating that the conversion should be done using base 2.

If you need that representation to code something like int i = 01010b, then i don''t think C# supports that.

Blew

Share this post


Link to post
Share on other sites
I was under the impression that in C/C++/C# you could declare a binary number by doing something to the effect of: int i = 0b110101; or somesuch.

Share this post


Link to post
Share on other sites
From the C# Language Specification:
quote:

2.4.4.2 Integer literals

Integer literals are used to write values of types int, uint, long, and ulong. Integer literals have two possible forms: decimal and hexadecimal.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!