如何将二进制值转换为数值 [英] How to convetr binary value to numeric

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

问题描述

如何将二进制数据类型的枚举值转换为数字值?

例如:
在SQL Server 2005中将000101010101(二进制)转换为341(十进制)

How do you convert a binary data type colume value to a numeric value?

For example:
Convert 000101010101 (binary) to 341 (decimal) in Sql Server 2005

推荐答案

根据图表几乎位于中途
According to the chart almost halfway down on this page[^], there is an implicit conversion between binary and almost all numeric types (except real and float).


如果您的二进制值为是字符串(按照SA的要求),下面的代码将为您提供帮助:
int i = Convert.ToInt32("000101010101", 2);此处2(第二个参数)表示第一个参数的基数(二进制的基数为2).要获得更多帮助,您可以阅读
MSDN文档以获得该方法.

对于Sql Server,请查看此链接.仅当提供数字(在输入字符串中)时,此UDF才能很好地工作,但要进行十六进制转换的情况除外,因此请在调用代码中加以注意.

希望对您有所帮助!
If your binary value is in string (as SA asked), below code will help you:
int i = Convert.ToInt32("000101010101", 2); here 2 (second parameter) denotes the base of the first parameter (base for binary would be 2). For further help you can read the MSDN documentation for this method.

For Sql Server have a look at this link. This UDF works well when supplied digits only (in the input string) except the case when you want hexadecimal conversion, so take care of that in your calling code.

Hope that helps!


尝试一下,可能对您有帮助

http://oraqa.com /2008/02/29/how-to-convert-binaryoctalhex-to-decimal-base-ten-number-in-sql/ [
try this, may this help you

http://oraqa.com/2008/02/29/how-to-convert-binaryoctalhex-to-decimal-base-ten-number-in-sql/[^]


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

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