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

问题描述

我试图在Excel中将 4503599627370495 转换为二进制文件。 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?

推荐答案

Thanx 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()大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 08:18