how to convert binary data into ascii codes

Community Trekker

Joined:

Jan 15, 2014

I have some analog data I need to convert it to binary basing on its value(done). Then I managed to put 8 bits together to make a binary data by jmp script. Where I need help is how to convert the binary data into text/number using ascii codes. I tried use blob to char but it reporting wrong data type....

I attached jmp table.

1 ACCEPTED SOLUTION

Accepted Solutions

Super User

Joined:

Jun 23, 2011

Solution

The binary numbers in your table do not always correspond to A-Z or 0-9. These show up: " # & 0 1 2 3 4 5 6 7 ? @ A B C D E F G H I J K L M N P Q R S T U V W X _ o { } ~

And in the many cases of non-printable ascii "characters" there will be empty cells in JMP.

I've probably misunderstood your goal, but try this formula, which will make an exception for all wl among {12, 13, 26, 27, 40, 41}.

If( Contains( {12, 13, 26, 27, 40, 41}, :wl ),

Char(

(Matrix(

{:Name( "0" ), :Name( "1" ), :Name( "2" ), :Name( "3" ), :Name( "4" ),

:Name( "5" ), :Name( "6" )}

)` * 2 ^ Index( 0, 6 )`)[1]

),

Hex To Char(

Right(

Hex(

(Matrix(

{:Name( "0" ), :Name( "1" ), :Name( "2" ), :Name( "3" ),

:Name( "4" ), :Name( "5" ), :Name( "6" )}

)` * 2 ^ Index( 0, 6 )`)[1],

"integer"

),

2

),

"us-ascii"

)

)

4 REPLIES

Super User

Joined:

Jun 23, 2011

There is probably a simpler way, but try to paste the code below into a column formula field in the posted data table. It should give the ascii character (the first argument of Hex() alone calculates the ascii decimal code)

Hex To Char(

Right(

Hex(

(Matrix(

{:Name( "0" ), :Name( "1" ), :Name( "2" ), :Name( "3" ), :Name( "4" ), :Name( "5" ), :Name( "6" )} )` * 2 ^ [0, 1, 2, 3, 4, 5, 6])[1],

"integer"

),

2

),

"us-ascii"

)

Community Trekker

Joined:

Jan 15, 2014

Thanks MS!

I know nothing about matrix usage in jmp. for the data I posted, my ultimate goal are A: convert "wl" 0~11, 14~25 and 28~39 to text composing A-Z and 0-9. B: Other "wl"s represent a 2 digit decimal number.

your script work for A but not for B.

Super User

Joined:

Jun 23, 2011

Solution

The binary numbers in your table do not always correspond to A-Z or 0-9. These show up: " # & 0 1 2 3 4 5 6 7 ? @ A B C D E F G H I J K L M N P Q R S T U V W X _ o { } ~

And in the many cases of non-printable ascii "characters" there will be empty cells in JMP.

I've probably misunderstood your goal, but try this formula, which will make an exception for all wl among {12, 13, 26, 27, 40, 41}.

If( Contains( {12, 13, 26, 27, 40, 41}, :wl ),

Char(

(Matrix(

{:Name( "0" ), :Name( "1" ), :Name( "2" ), :Name( "3" ), :Name( "4" ),

:Name( "5" ), :Name( "6" )}

)` * 2 ^ Index( 0, 6 )`)[1]

),

Hex To Char(

Right(

Hex(

(Matrix(

{:Name( "0" ), :Name( "1" ), :Name( "2" ), :Name( "3" ),

:Name( "4" ), :Name( "5" ), :Name( "6" )}

)` * 2 ^ Index( 0, 6 )`)[1],

"integer"

),

2

),

"us-ascii"

)

)

Community Trekker

Joined:

Jan 15, 2014

thanks MS.

Sorry, in fact that I realized later that  "wl" 0~11, 14~25 and 28~39 are 2 digits decimal number, which only need be convert to decimal.