bin2dec for numbers longer than 10 bits in excel

左心房为你撑大大i 提交于 2020-12-09 05:02:40

问题


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?


回答1:


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.

   




回答2:


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.



来源:https://stackoverflow.com/questions/35693029/bin2dec-for-numbers-longer-than-10-bits-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!