如何存储的十六进制字符串在android的整数变量? [英] How to store Hex string in an Integer variable in android???

查看:244
本文介绍了如何存储的十六进制字符串在android的整数变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下code intArray [i]于十六进制格式像素的RGB门店值(例如:为0xffff0000)......的方法hsvToRgb()给出窥知RGB的整数值(如:15777252),但我需要更改后,在原有的十六进制格式备份的RGB值。
第二行给了我,但它的字符串....我该怎么办存储此字符串值回阵? ... 请帮帮我。

  INT迪斯科= hsvToRgb(HSV);       hexColor =的String.format(为0x%06X(0XFFFFFF&安培;迪斯科));
       intArray [I] = Integer.valueOf(将String.valueOf(迪斯科),16);


解决方案

有作为一个十六进制整数与一个十进制格式整数没有这样的事。值的位/字节重新presentation是相同的。例如,十进制值 15777252 是十六进制值 0xF0BDE4 。 (您可以使用谷歌转换:十六进制15777252搜索)。

您可以直接使用迪斯科值。如果你想打印出来的十六进制再presentation,使用的 Integer.toHexString()

关于格式。想想看这样的...计算机重新presents价值为一系列位。举例来说,让我们挑选使用8位是一个随机数,并重新present: 01110101 。使用位串重新present更大的数字会得到很长的非常快,所以十六进制经常被使用。十六进制等效为: 65 。按照惯例,我们一般通过 0X precede值时,它的十六进制。这给了我们 0x65 。非程序员往往在基地不过10(而不是16为基数)更自然地处理。在底座10相同数量为 101

您可以用一些code看到这一点:

 最终int值= 0x65; //我们可以以十六进制声明它
最终诠释sameValue = 101; //或十进制的System.out.println(值); //在基地10输出;打印101
的System.out.println(Integer.toHexString(值)); //在基地16个输出;版画65
的System.out.println(Integer.toBinaryString(值)); //在基地2个输出;版画1100101的System.out.println(+(价值== sameValue)); //输出真

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.

       int disco = hsvToRgb(hsv);

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

解决方案

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").

You can use the disco value directly. If you want to print it out in a hex representation, use 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.

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"

这篇关于如何存储的十六进制字符串在android的整数变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆