如何在android中的Integer变量中存储十六进制字符串???

时间:2022-07-14 15:46:02

In the following code intArray[i] stores RGB values of pixels in hex format(eg:0xffff0000) .... The method hsvToRgb() gives bak an integer value of RGB (eg:15777252) but i need back the rgb value in the original hex format after changes. The second line gives me that but its a string ....What do i do to store this string value back into the array? ... please help me.

在下面的代码中,intArray [i]以十六进制格式存储像素的RGB值(例如:0xffff0000)....方法hsvToRgb()给bak一个RGB的整数值(例如:15777252),但我需要返回rgb值更改后的原始十六进制格式。第二行给了我但是它是一个字符串....我该怎么做才能将这个字符串值存回数组? ... 请帮帮我。

       int disco = hsvToRgb(hsv);

       hexColor = String.format("0x%06X", (0xffffff & disco));
       intArray[i] = Integer.valueOf(String.valueOf(disco), 16);

1 个解决方案

#1


6  

There's no such thing as a "hex format" integer versus a "decimal format" integer. The bit/byte representation of the value is the same. For example, the decimal value 15,777,252 is the hex value 0xF0BDE4. (You can use Google to convert: search "15777252 in hex").

没有“十六进制格式”整数与“十进制格式”整数之类的东西。值的位/字节表示相同。例如,十进制值15,777,252是十六进制值0xF0BDE4。 (您可以使用Google进行转换:搜索“15777252 in hex”)。

You can use the disco value directly. If you want to print it out in a hex representation, use Integer.toHexString().

您可以直接使用迪斯科价值。如果要以十六进制表示形式打印出来,请使用Integer.toHexString()。

Regarding the format. Think of it like this ... The computer represents the value as a series of bits. By way of example, let's pick a random number and represent it using 8 bits: 01110101. Using a bit string to represent bigger numbers would get very long very quickly, so hexadecimal is often used. The hex equivalent is: 65. By convention, we usually precede the value by 0x when it's in hex. That gives us 0x65. Non-programmers tend to deal more naturally in base 10 however (rather than base 16). The same number in base 10 is 101.

关于格式。可以这样想......计算机将值表示为一系列位。举例来说,让我们选择一个随机数并使用8位表示它:01110101。使用位串来表示更大的数字将非常快,因此经常使用十六进制。十六进制等效值是:65。按照惯例,当它是十六进制时,我们通常在值前面加上0x。这给了我们0x65。然而,非程序员倾向于在基数10中更自然地处理(而不是基数16)。基数10中的相同数字是101。

You can see this with some code:

你可以用一些代码看到这个:

final int value = 0x65;                            // we can declare it in hex
final int sameValue = 101;                         // or in decimal

System.out.println(value);                         // output in base 10; prints "101"
System.out.println(Integer.toHexString(value));    // output in base 16; prints "65"
System.out.println(Integer.toBinaryString(value)); // output in base 2; prints "1100101"

System.out.println(""+(value == sameValue));       // prints "true"

#1


6  

There's no such thing as a "hex format" integer versus a "decimal format" integer. The bit/byte representation of the value is the same. For example, the decimal value 15,777,252 is the hex value 0xF0BDE4. (You can use Google to convert: search "15777252 in hex").

没有“十六进制格式”整数与“十进制格式”整数之类的东西。值的位/字节表示相同。例如,十进制值15,777,252是十六进制值0xF0BDE4。 (您可以使用Google进行转换:搜索“15777252 in hex”)。

You can use the disco value directly. If you want to print it out in a hex representation, use Integer.toHexString().

您可以直接使用迪斯科价值。如果要以十六进制表示形式打印出来,请使用Integer.toHexString()。

Regarding the format. Think of it like this ... The computer represents the value as a series of bits. By way of example, let's pick a random number and represent it using 8 bits: 01110101. Using a bit string to represent bigger numbers would get very long very quickly, so hexadecimal is often used. The hex equivalent is: 65. By convention, we usually precede the value by 0x when it's in hex. That gives us 0x65. Non-programmers tend to deal more naturally in base 10 however (rather than base 16). The same number in base 10 is 101.

关于格式。可以这样想......计算机将值表示为一系列位。举例来说,让我们选择一个随机数并使用8位表示它:01110101。使用位串来表示更大的数字将非常快,因此经常使用十六进制。十六进制等效值是:65。按照惯例,当它是十六进制时,我们通常在值前面加上0x。这给了我们0x65。然而,非程序员倾向于在基数10中更自然地处理(而不是基数16)。基数10中的相同数字是101。

You can see this with some code:

你可以用一些代码看到这个:

final int value = 0x65;                            // we can declare it in hex
final int sameValue = 101;                         // or in decimal

System.out.println(value);                         // output in base 10; prints "101"
System.out.println(Integer.toHexString(value));    // output in base 16; prints "65"
System.out.println(Integer.toBinaryString(value)); // output in base 2; prints "1100101"

System.out.println(""+(value == sameValue));       // prints "true"