How to convert decimal value to binary value in another column?
Hi @Liranlev : Here ya go (you can choose whatever base you like in the Hex function).
Hex( X, base( 2 ) ), where X is the decimal value.
OK
Let's say for example now I have a column with value "1011"
Do you have any idea how can I seperate it to 4 columns?
1 0 1 1
Here is one suggestion (create new column which you can use with Text to Columns as it doesn't allow using "" as limiter)
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(1),
Compress File When Saved(1),
New Column("Column 1", Character, "Nominal", Set Values({"1011"}))
);
dt << new column("Separated", Character, "Nominal", Formula(
Concat Items(Words(:Column 1, ""), "|")
));
dt << Text to Columns(columns(:Separated), Delimiters("|"));
Allow the Text to Columns() function to specify an empty delimiter
It's great but I have some problem.
1. It should open new columns in the table I work in.
2. How can it take values from specific column instead of writing "1011"?
I'm not sure what you mean with either of those.
To learn JMP scripting Scripting Guide (jmp.com)
Hi @Liranlev: Word( 1, Y, "" ) will give the first digit, Word( 2, Y, "" ), will give the 2nd, etc., where Y is the binary representation.
But I don't know how long my binary number. I should use loop
There is no need for a loop.....Taking @jthi example and adding a second row to his example table, one can see that it will add as many columns as found.
Now the additional issue that one might want the binary columns to line up and have the same number of columns generated. Here is a modification that accomplishes that
Names Default To Here( 1 );
dt = New Table( "Untitled",
Add Rows( 1 ),
Compress File When Saved( 1 ),
New Column( "Column 1", Character, "Nominal", Set Values( {"1011", "11010110"} ) )
);
max length = Col Max( Length( :Column 1 ) );
fill = Repeat( "0", max length );
For Each Row(
:Column 1 = Substr( fill, 1, max length - Length( :Column 1 ) ) || :Column 1
);
dt << New Column( "Separated",
Character,
"Nominal",
Formula( Concat Items( Words( :Column 1, "" ), "|" ) )
);
dt << Text to Columns( columns( :Separated ), Delimiters( "|" ) );