cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
kuanaunwei
Level III

How to Convert a 32bit Binary data to Decimal in jmp Script

Hi,

 

I have a few sets of 32bit binary data that I want to convert it to Decimal for mathematical calculation purposes.

 

Can be any random 32bit binary data.

 

So far i have tried out these:

1. Formula(base("32bit Binary Data",2))

2. BLOB

3. Hex to Decimal (Char to Hex ("32bit Binary Data"))

 

32bit Binary Data:

00000000000110001101011110111000
00000000000111010000000001110100
00000000000111011001001000100000
00000000000110011001010111101000
00000000000111110001111110110101
00000000000110011110000101110000
00000000000111001000111010001000
00000000000111001000110010100000
00000000000110110111000001011110
00000000000111011101100101010000
00000000000110101100110100110100
00000000000110110011100100001011
00000000000111100111010111100110
00000000001000001111101010110100
00000000000111010010000011101111
00000000000110111110010010001000
00000000000111011011100111100100
00000000000110111010111001101100
00000000000111000111110001001100

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

@ThuongLe  provided a very nice piece of JSL.  Your modification into a column's formula is what is causing the issue.  Try this formula.  The code is a little more generic and also, it forces the "sum" variable to be the last item executed in the formula, which is what is returned to the value for the row the formula is working on

sum = 0;
end = Length( :Name("1F1") );
For( i = 1, i <= end, i++,
	sum = sum + Num( Substr( :Name("1F1") , (end + 1) - i, 1 ) ) * 2 ^ (i - 1)
);
sum;
Jim

View solution in original post

6 REPLIES 6
ThuongLe
Level IV

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

Please read this, JMP15 has a built-in function for this kind of conversion:

All your base are belong to us (in JSL) 

Thuong Le
kuanaunwei
Level III

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

I do not have JMP15 version installed. Currently using JMP 11 Pro. So this syntax cant be applied. I have also tried out those syntax
ThuongLe
Level IV

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

I have wrote a quick script, you can modify to become a function:

a = "00000000000110001101011110111000";
sum = 0;

for(i = 1, i<= 32, i++,
	sum = sum + num(substr(a, 33-i, 1))*2^(i-1);
);
Thuong Le
kuanaunwei
Level III

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

I tried out the function script it is working. However, I am trying to create a new column with the decimal data. It seems to be blank on that column 1F1-DEC.

Below is my script:

dt2 << New Column ("1F1", Character, Nominal, Formula(:Name( "0x905" ) || :Name( "0x904" )));
dt2 << New Column ("1F1-DEC", Numeric, Nominal, Formula(sum = 0;

for(i = 1, i<= 32, i++,
sum = sum + num(substr(:Name("1F1"), 33-i, 1))*2^(i-1);
);););



txnelson
Super User

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

@ThuongLe  provided a very nice piece of JSL.  Your modification into a column's formula is what is causing the issue.  Try this formula.  The code is a little more generic and also, it forces the "sum" variable to be the last item executed in the formula, which is what is returned to the value for the row the formula is working on

sum = 0;
end = Length( :Name("1F1") );
For( i = 1, i <= end, i++,
	sum = sum + Num( Substr( :Name("1F1") , (end + 1) - i, 1 ) ) * 2 ^ (i - 1)
);
sum;
Jim
kuanaunwei
Level III

Re: How to Convert a 32bit Binary data to Decimal in jmp Script

@txnelsonIT WORKS!!! Thanks alot! I have been working on this for quite some time.