10進数を2進数に変換する<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />データの列(10進数)をバイナリ(8ビット)に変換してから、4LSBを4MSBのデータの次の列に連結する必要があります。JMPで少なくとも10進データを2進に変換する方法はありますか?
Re: 10 進数を 2 進数に変換する前に述べたように:
こんにちは - 必要なことを行うために以下を調整できますか?
<SPAN>// Function to convert an integer into any positive base up to hexadecimal;</SPAN><BR />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;
と:
問題ありません - 追加の "if" 句は n=0 を特別なケースとして扱います:
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);
(n は非負の整数であり、基数は正の整数であると想定しています。)
Re: 10進数を2進数に変換するこんにちは。必要なことを行うために、次のことを適応させることができますか?
// 整数を 16 進数までの任意の正の基数に変換する関数。
ベース= 関数( {n,nbase }, {デフォルト ローカル},
ndash = 「」 ;
数字= 「0123456789ABCDEF」 ;
その間( n > 0,
剰余= に対して ( n , nbase ) ;
newdigit = 部分文字列 (桁数, ( 1 +余り) , 1 ) ;
ndash =新しい数字|| ndash ;
n= (n -剰余) / nbase ;
);
ndash;
);
// バイナリで動作していることを示すためにいくつかの数値を出力します。
のために( i = 1, i <= 32, i++、見せる( チャー( i ) || 「=」 ||ベース( i, 2 ) ) );
// または、データ テーブルにいくつかの新しい列を作成して入力します。
dt= 新しいテーブル( 「数の基数」, 新しいコラム( 「ん」,数値,値(索引( 1, 32 ) ) ) );
基数= {2, 3, 8, 10, 12, 16}; // いくつかのよく知られた数値基数。
のために( i = 1, i <= N 個のアイテム(基数), i++、
k=基数[ i ];
dt<< 新しいコラム( 「ベース」|| チャー( k ),キャラクター);
のために( j = 1, j <= N列(dt ), j++、
カラム(dt, (「ベース」|| チャー( k )) )[j] =ベース(j, k ) );
);
// プログラムの終了;
Re: 10進数を2進数に変換するこれは始まりです。しかし、関数baseは0を2進数の0に変換できないようです。