cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
justvince
Level III

Convert decimal to Binary

I need to convert Columns of data (decimal) to binary (8 bit) , then concantenate say the 4 LSB to the next column of data with the 4 MSB.  Is there a way to at least convert decimal data to binary in JMP? 

1 ACCEPTED SOLUTION

Accepted Solutions
Duane_Hayes
Staff (Retired)

Re: Convert decimal to Binary

As previously stated:

 

Hi - can you adapt the following to do what you need?

 

 

// Function to convert an integer into any positive base up to hexadecimal;
base = Function( {n, nbase}, {default local},        ndash = "";        digits= "0123456789ABCDEF";      While( n > 0,               remainder= Mod( n, nbase );               newdigit= Substr( digits, (1 + remainder), 1 );               ndash= newdigit || ndash;               n= (n - remainder)/ nbase;        ); ndash; );   // Print out a few numbers to show it working in binary;   For( i = 1, i <= 32, i++, Show( Char( i ) || " = " || base( i, 2 ) ) );   // Or create some new columns in a data table and fill them;   dt = New Table( "Number Bases", New Column( "N", numeric, values( Index( 1, 32 ) ) ) );   numberbase = {2, 3, 8, 10, 12, 16}; // Some familiar number bases;   For( i = 1, i <= N Items( numberbase ), i++,      k= numberbase[i];      dt<< New Column( "Base "|| Char( k ), character );      For( j = 1, j <= N Row( dt ), j++,      Column( dt, ("Base "|| Char( k )) )[j] = base( j, k ) );      );   // End of program;

 

 

And:

 

No problem - an extra "if" clause will treat n=0 as a special case:

 

 

base = function({n, base}, {default local}, ndash = ""; digits = "0123456789ABCDEF";
if(n > 0, while(n > 0, remainder = mod(n, base); newdigit = substr(digits, (1 + remainder), 1);
ndash = newdigit || ndash; n = (n - remainder) / base), ndash = "0"); ndash);

 

 

(I'm assuming that n is a non-negative integer, and that base is a positive integer.)

Duane Hayes

View solution in original post

4 REPLIES 4

Re: Convert decimal to Binary

Hi - can you adapt the following to do what you need?

// Function to convert an integer into any positive base up to hexadecimal;

base = Function( {n, nbase}, {default local},

       ndash = "";

       digits= "0123456789ABCDEF";

     While( n > 0,

              remainder= Mod( n, nbase );

              newdigit= Substr( digits, (1 + remainder), 1 );

              ndash= newdigit || ndash;

              n= (n - remainder)/ nbase;

       );

ndash;

);

// Print out a few numbers to show it working in binary;

For( i = 1, i <= 32, i++, Show( Char( i ) || " = " || base( i, 2 ) ) );

// Or create some new columns in a data table and fill them;

dt = New Table( "Number Bases", New Column( "N", numeric, values( Index( 1, 32 ) ) ) );

numberbase = {2, 3, 8, 10, 12, 16}; // Some familiar number bases;

For( i = 1, i <= N Items( numberbase ), i++,

     k= numberbase[i];

     dt<< New Column( "Base "|| Char( k ), character );

     For( j = 1, j <= N Row( dt ), j++,

     Column( dt, ("Base "|| Char( k )) )[j] = base( j, k ) );

     );

// End of program;

justvince
Level III

Re: Convert decimal to Binary

It is a start.  But it appears the function base will not convert a zero to binary 0,

Re: Convert decimal to Binary

No problem - an extra "if" clause will treat n=0 as a special case:

base = function({n, base}, {default local}, ndash = ""; digits = "0123456789ABCDEF";

if(n > 0, while(n > 0, remainder = mod(n, base); newdigit = substr(digits, (1 + remainder), 1);

ndash = newdigit || ndash; n = (n - remainder) / base), ndash = "0"); ndash);

(I'm assuming that n is a non-negative integer, and that base is a positive integer.)

Duane_Hayes
Staff (Retired)

Re: Convert decimal to Binary

As previously stated:

 

Hi - can you adapt the following to do what you need?

 

 

// Function to convert an integer into any positive base up to hexadecimal;
base = Function( {n, nbase}, {default local},        ndash = "";        digits= "0123456789ABCDEF";      While( n > 0,               remainder= Mod( n, nbase );               newdigit= Substr( digits, (1 + remainder), 1 );               ndash= newdigit || ndash;               n= (n - remainder)/ nbase;        ); ndash; );   // Print out a few numbers to show it working in binary;   For( i = 1, i <= 32, i++, Show( Char( i ) || " = " || base( i, 2 ) ) );   // Or create some new columns in a data table and fill them;   dt = New Table( "Number Bases", New Column( "N", numeric, values( Index( 1, 32 ) ) ) );   numberbase = {2, 3, 8, 10, 12, 16}; // Some familiar number bases;   For( i = 1, i <= N Items( numberbase ), i++,      k= numberbase[i];      dt<< New Column( "Base "|| Char( k ), character );      For( j = 1, j <= N Row( dt ), j++,      Column( dt, ("Base "|| Char( k )) )[j] = base( j, k ) );      );   // End of program;

 

 

And:

 

No problem - an extra "if" clause will treat n=0 as a special case:

 

 

base = function({n, base}, {default local}, ndash = ""; digits = "0123456789ABCDEF";
if(n > 0, while(n > 0, remainder = mod(n, base); newdigit = substr(digits, (1 + remainder), 1);
ndash = newdigit || ndash; n = (n - remainder) / base), ndash = "0"); ndash);

 

 

(I'm assuming that n is a non-negative integer, and that base is a positive integer.)

Duane Hayes

Recommended Articles