=dec2bin(a1)

KEN_KACEL

Member
Join Date
Nov 2002
Location
NORTH COUNTRY
Posts
162
I have been trying to get a DDE word into a BINary format in excel but some how Bill Gates thinks that a 12bit word is all we need, not 16bit and then he puts it in a decimal value of 1s and 0s so if you add a one to your binary value you get:

1010101
+ 1
----------------
1010102

How do I get a binary number of 16bits of 1s and 0s into a cell?

I must be missing something because this should be basic stuff. I cut my teeth on this in school and would expect a spreadsheet to have this feature.
 
KEN_KACEL,

How do I get a binary number of 16bits of 1s and 0s into a cell?

Import the 16-bit binary number as TEXT (example: "101010111100111"". Then write an Excel Macro command to convert it from binary to decimal, or whatever number system you are working in. You will need to know what type of binary numbers you are dealing with: 2's Complement, 1's Complement, Negatives, etc., and write your Macro to convert according to what type of binary number you have.
 
I did it differently by taking the I:1.0 value in cell C4

=IF(C4<1,65536-ABS(C4),C4) in cell E4 ;change to unsigned integer

bit 0 =E4/2 cell D8 =FLOOR(D8,1) in cell E8 =IF(D8<>E8,1,0) ;
bit 1 =E8/2 cell D9 =FLOOR(D9,1) in cell E9 =IF(D9<>D9,1,0)
bit 2
.
.
.
.
bit 15

so a column of 1s and 0s can be viewed and I can add to the integer value if need be.

Still think the =dec2bin instruction should be for 16bits vs 12bits and should be a true radix of base 2 and not base 10. But I expect to much from the PC world.
 

Function Number2Bin(Source As Integer) As String

'This function will convert an integer value in -32768...32767 range
'to a string representing binary equivalent

Dim bit As Long, tempstr As String, tempchar As String
tempstr = vbNullString
If Sgn(Source) = -1 Then tempstr = "1"
For bit = 14 To 0 Step -1
tempchar = Trim(Str((Source \ (2 ^ bit)) And &H1))
tempstr = tempstr & tempchar
Next bit
Number2Bin = tempstr
End Function
-------------------------------------------------------------------



Try this in Excel VBA. Might need some debugging but should work.
 
Back
Top Bottom