使用带有大量DEC2BIN() [英] Using DEC2BIN() with large numbers

查看:115
本文介绍了使用带有大量DEC2BIN()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图 4503599627370495 转换成二进制在Excel中。 DEC2BIN()返回#NUM!错误,因为DEC2BIN无法处理如此大的数字。

I'm trying to convert 4503599627370495 into binary in Excel. DEC2BIN() returns #NUM! error because DEC2BIN cannot handle such a large number.

这是我如何能够使它发挥作用?有什么想法

Any thoughts on how I might be able to make it work?

推荐答案

感谢名单JustinDavies - 这是我需要的,但如果通过了​​-ve数它进入一个死循环。我的修改:

Thanx JustinDavies - that was just what I needed, but it went into an endless loop if passed a -ve number. My modification:

Function DecToBin(ByVal DecimalIn As Variant, Optional NumberOfBits As Variant) As String
  DecToBin = ""
  DecimalIn = CDec(DecimalIn)
  If DecimalIn < 0 Then
    DecToBin = "Error - Number negative"
    Exit Function
  End If
  Do While DecimalIn <> 0
    DecToBin = Trim$(Str$(DecimalIn - 2 * Int(DecimalIn / 2))) & DecToBin
    DecimalIn = Int(DecimalIn / 2)
  Loop
  If Not IsMissing(NumberOfBits) Then
    If Len(DecToBin) > NumberOfBits Then
      DecToBin = "Error - Number too large for bit size"
    Else
      DecToBin = Right$(String$(NumberOfBits, "0") & _
      DecToBin, NumberOfBits)
    End If
  End If
End Function

这篇关于使用带有大量DEC2BIN()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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