-2

int を 16 進数に変換する関数があります。この関数では、シークバーの値を 0 から 100 の間で取得します。次に、いくつかの変更を行い、最後にそれを 16 進数に変換します。

    private String decimalToHex(int i) {

    /**Conversion to decimal of the seekbar's % value*/
    int_value = ((i * 20480) / 100) * -1;
    int_value = -20480 - int_value;

    /**Conversion to hex*/
    hex_value = Integer.toString(int_value, 16);
    //hex_value = Integer.toHexString(c2_final);

    return hex_value;
}

値が 52であると仮定しましょうint i。これは次の値を取得します。int_value = -9831

この値を 16 進数に変換すると、-2667. しかし、これは私が必要とする値ではありません。

16 進数の結果として "D999" のような値が得られるように変換する必要があります。この値は、値を 1 で補うことによって取得します (別名、~演算子)。これは、値-9831を posveに変換し9831、次に 1 を減算して get を取得9830し、最後にビットを変更し55705て 16 進数で となる値を取得するようなものD999です。

この最後のことをどうすればいいですか?ビットを変える?

C のコード:

if (int_value < 0) {

        c2_value = int_value * -1;
        c2_value = c2_value - 1;
        c2_final = ~c2_value;
    }
4

1 に答える 1