Decimal to binary conversion for large numbers in Excel

后端 未结 12 2119
长情又很酷
长情又很酷 2020-12-14 02:31

I have some large numbers in an Excel sheet and I want to convert them to binary.

e.g.

12345678  
965321458  
-12457896
12条回答
  •  失恋的感觉
    2020-12-14 02:54

    Without VBA and working with negative numbers as well (here: sint16), however, taking much more space:

    You can download the excel file here: (sorry, didn't know where to put the file) int16 bits to decimal.xlsx

    or alternatively follow these steps (if your Excel is not in English, use Excel Translator to "translate" the formula into your MS Office language):

    1. Enter the binary number in 4-bit nibbles (A4 = most significant to D4 = least significant) like shown in the screenshot. Enter all 4 digits (even if starting with 0) and format them as "text"
    2. Enter formula in F4:
        =IF(NUMBERVALUE(A4)>=1000,TRUE,FALSE)
    
    1. Enter the letter "A" in G2-J2, "B" in K2-N2, "C" in O2-R2, "D" in S2-V2

    2. Enter "1" in G3, K3, O3 and S3; "2" in H3, L3, P3 and T3; "3" in I3, M3, Q3 and U3; "4" in J3, N3, R3 and V3

    3. In G4, enter:

        =MID(INDIRECT(G$2&ROW()),G$3,1)
    
    1. Copy the formula to H4-V4

    2. In X4, enter:

        =IF(G4="1",0,1)
    
    1. Copy X4 to Y4-AM4

    2. In BD3 enter "1"

    3. In BC4, enter:

        =IF((AM$4+BD3)=2,1,0)
    
    1. IN BD4, enter:
        =IF((AM$4+BD3)=2,0,IF((AM$4+BD3)=1,1,0))
    
    1. Copy BD4 and BD4 and insert it 15 times diagonally one row further down and one column further left (like in the screenshot), i.e. insert it to BB5 and BC5, then BA6 and BB6, ..., AN19 and AO19.

    2. In AO20, enter "=AO19"; in AP20, enter "=AP18" and so on until BD20 ("=BD4") - i.e. bring down the numbers into one line as seen in the screenshot

    3. In BE20, enter (this is your result):

        =IF(F4=FALSE,BIN2DEC(A4&B4)*2^8+BIN2DEC(C4&D4),-1*(BIN2DEC(AO20&AP20&AQ20&AR20&AS20&AT20&AU20&AV20)*2^8+BIN2DEC(AW20&AX20&AY20&AZ20&BA20&BB20&BC20&BD20)))
    

提交回复
热议问题