小数在C#二进制转换 [英] Decimal to binary conversion in c #

查看:190
本文介绍了小数在C#二进制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将十进制转换没有成二进制在C#

How to convert a decimal no into binary in c #

现在我使用类似:

      String str="8";
      String Ans= Convert.ToInt32(str,2).ToString();

但它抛出一些例外。

But it's throwing some Exceptions.

如何做到这一点?

推荐答案

您示例有pss​​ed为字符串的整数EX $ P $。比方说,你的整数​​实际上是一个整数,你想利用整数并将其转换为二进制字符串。

Your example has an integer expressed as a string. Let's say your integer was actually an integer, and you want to take the integer and convert it to a binary string.

int value = 8;
string binary = Convert.ToString(value, 2);

它返回1000。

Which returns 1000.

这篇关于小数在C#二进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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