方便,快捷的方式为int转换为二进制? [英] easy and fast way to convert an int to binary?

查看:107
本文介绍了方便,快捷的方式为int转换为二进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所寻找的是在C#中类似PHP的 decbin 功能。这个函数转换小数其作为一个字符串表示。



例如,当使用 decbin(21)返回 10101 作为结果。



我发现的this功能基本上我想要做什么,但也许有更好的/更快的方式?


解决方案

  VAR的结果= Convert.ToString(号,2); 



- 几乎为(否则无用)转换类。


What I am looking for is something like PHPs decbin function in C#. That function converts decimals to its representation as a string.

For example, when using decbin(21) it returns 10101 as result.

I found this function which basically does what I want, but maybe there is a better / faster way?

解决方案

var result = Convert.ToString(number, 2);

– Almost the only use for the (otherwise useless) Convert class.

这篇关于方便,快捷的方式为int转换为二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆