Reputation: 71
I have an excel with 28 position binary numbers. I need to convert them to decimal numbers, but function bin2dec don't work with numbers longer than 10 bits. Can anyone help me with this?
Upvotes: 7
Views: 35743
Reputation: 1
Improving @user4039065 answer, by mentioning "Signed" in Column A and from the Binary value in Column B info about following could be used to find value from 2's complement representation of signed values,
=LET(binaryval,B2,sign,IF(A2="Signed",1,0),length,LEN(binaryval),offset,IF(sign,-1*(2^(length-1))*--MID(binaryval,1,1),0), sum,SUMPRODUCT(--MID(binaryval,length+1-ROW(INDIRECT("1:"&length-sign)),1),(2^(ROW(INDIRECT("1:"&length-sign))-1))),offset+sum)
Sample : 1
Upvotes: 0
Reputation: 365
Use the new spilling formulas (see this and that) to support any number up to 1.7976931348623158e+308
, limited by Excel's 15 digits of precision and largest allowed numbers via formula.
Practically speaking that's:
999,999,999,999,999
49 bits
in any combination50 bits
as long as decimal value is less than 1 quadrillion1024 bits
/ 309 decimal digits
as long as you only care about 15 decimal digits of precision and it's less than 1.7...e+308
Copy this formula and replace A2
with whatever cell you want to convert. The formula works by extracting each digit in the string with MID
, multiplying it by the appropriate power 2^x
, then calculates the sum of all those individual numbers. LET
is not required, but lets you substitute A2
in just one spot instead of several.
=LET(number, A2, nBitBin2Dec,LAMBDA(a,SUM(MID(a,SEQUENCE(LEN(a)),1)*2^SEQUENCE(LEN(a),1,LEN(a)-1,-1))),nBitBin2Dec(number))
For nicer display of these numbers e.g. grouping digits into sets of ten, see my answer at https://stackoverflow.com/a/78069101/6047827.
Here are the raw numbers to make copy-paste easier. Many thanks to Mobilefish Big number converter for converting the 308 digits of ="999999999999999" & CONCAT(ROUND(MAKEARRAY(293,1,LAMBDA(r,c,0)),0))
into binary for me, and similar conversions.
011
3
1011011011011011011011011101
191,739,613
11100011010111111010100100110001100111111111111111
999,999,999,999,999
1000111001100111100111000010111101011110010001001101011101111001111111111000000110000011100101100011011100010000110000000101000000010111111100101010101010000100001011100100101010111011010100010010011111011101010111111110011000100001000100100100011110100000001011010010000010111100011101001011100101101001100011110000000101110000111101011100111000111100100110000101110110110000100011001100111001000101001100110000010110100101101110011000110011101010111111100111110110001011011100101100110110000100000010111001000000110100100011111001111000011101010101100010000011100101001101111000111000101110000011011111110101001100110101111011100001011100001011101010000000110110100100100010111100100110001101111001011001111110111001100100100101100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
9.99999999999999E+307
99999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1.7976931348623158e+308
179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497791
Upvotes: 1
Reputation: 31
I brute forced it with the math, may be inelegant, but for a 16 bit number where leading 0's will be displayed this works and can easily be adapted to longer strings
This works well if you are working with fixed length words, like verifying values in memory, BIT registers, etc.
16 bit
=BIN2DEC(LEFT(R5,8))*2^8+BIN2DEC(RIGHT(R5,8))
32 bit could be
=BIN2DEC(MID(R10,1,8))*2^24+BIN2DEC(MID(R10,9,8))*2^16+BIN2DEC(MID(R10,17,8))*2^8+BIN2DEC(MID(R10,25,8))
Again, this works if you have a fixed length input, leading zeros are displayed.
Upvotes: 3
Reputation:
Use the following formula to mimic a BIN2DEC function that coverts larger than 10 bits.
=SUMPRODUCT(--MID(A2,LEN(A2)+1-ROW(INDIRECT("1:"&LEN(A2))),1),(2^(ROW(INDIRECT("1:"&LEN(A2)))-1)))
Remember that Excel has a numerical precision of 15 digits. If you want 28 digits, format the cell as Text or preface the string of digits with a single tick (e.g. '
) as a PrefixCharacter property.
Upvotes: 13