十進数を二進数表記(文字列型)に変換する

先頭ビットから降順

string Dec2Bin(integer dec){
    string bin;
    integer mask = 0x80000000;
    list separation = ["", "", "", " "];
    integer i;
    for (i=0; i<32; i++){
        bin += (string)((dec&mask) / mask) + llList2String(separation, i%4);
        dec = dec<<1;
    }
    return llStringTrim(bin, STRING_TRIM);
}
 
// ----- (ex
// Dec2Bin(1000) => 0000 0000 0000 0000 0000 0011 1110 1000
// Dec2Bin(0)    => 0000 0000 0000 0000 0000 0000 0000 0000

最終ビットから昇順

string Dec2Bin(integer dec){
    string bin;
    integer mask = 1;
    list separation = ["", "", "", " "];
    integer i;
    for (i=0; i<32; i++){
        bin = llList2String(separation, i%4) + (string)(dec&mask) + bin;
        dec = dec>>1;
    }
    return llStringTrim(bin, STRING_TRIM);
}
 
// ----- (ex
// Dec2Bin(1000) => 0000 0000 0000 0000 0000 0011 1110 1000
// Dec2Bin(0)    => 0000 0000 0000 0000 0000 0000 0000 0000
string Dec2Bin(integer dec){
    string bin = (string)(dec&1);
    integer mask = 1;
    list separation = ["", "", "", " ", ""];
    for (dec=dec>>1&0x7fffffff; dec; dec=dec>>1){
        bin = llList2String(separation, llStringLength(bin)%5) + (string)(dec&mask) + bin;
    }
    return llStringTrim(bin, STRING_TRIM);
}
 
// ----- (ex
// Dec2Bin(1000) => 11 1110 1000
// Dec2Bin(0)    => 0