- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to convert decimal value to binary value in another column?
How to convert decimal value to binary value in another column?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
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"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
I'm not sure what you mean with either of those.
- "Open new columns"? you open tables, not columns in JMP. If you wish to refer columns, what is "new" column?
- 1011 isn't written there to anywhere else besides column which is used for the formula reference. So create formula column using your column and it should work.
To learn JMP scripting Scripting Guide (jmp.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
Hi @Liranlev: Word( 1, Y, "" ) will give the first digit, Word( 2, Y, "" ), will give the 2nd, etc., where Y is the binary representation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
But I don't know how long my binary number. I should use loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to convert decimal value to binary value in another column?
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( "|" ) );