简体   繁体   中英

How do I Convert Integer value to Binary value as a string in C#?

Not sure if I worded the title correctly, so my apologies.

I want to simply convert an integer to strings that hold the binary representation of that integer.

Example :
116 would convert to "1110100"

Is there anything built into .Net or will I need to write a small parsing algorithm?

This will do it:

// bin = "1110100"
var bin = Convert.ToString(116, 2)

The second parameter specifies which base to convert to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM