最近在项目中遇到了这样的需求,需要写一个方法来将RGB(255,255,255)这种格式转换成十六进制来使用,下面我将自己用到方法写一下:
final static char[] digits = { ‘0′, ‘1′, ‘2′, ‘3′, ‘4′, ‘5′, ‘6′, ‘7′, ‘8′, ‘9′, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ’s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’ };
public static String toUnsignedString(int param, 4)
{
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift;
int mask = radix – 1;
do
{
buf[--charPos] = digits[i & mask];
i >>>= shift;
}
while (i != 0);
return new String(buf, charPos, (32 – charPos));
}
很多人在开始学习j2me的时候遇到的第一个问题就是如何配置j2me的开发环境,我一般用的是eclipse开发,所以在这里说一下在eclipse中如何配置j2me的开发环境: