1. java 中如何将字符串转换成16位bit型数据
String s = "a";
int[] i = s.toCharArray();
static String Integer.toBinaryString(i[0]);
希望有帮助
2. 使用JAVA如何去生成大量16位的并且是顺序递增的数字串
你定义一个string str = "0000000000000000";
然后弄出那个递增的数字。然后截取这个数字的长度,
数字也转换成字符串 str1
然后是substring(str+str1,str1.length(),16);
3. java生成唯一标识符有什么用
有时我们不依赖于数据库中自动递增的字段产生唯一ID,比如多表同一字段需要统一一个唯一ID,这时就需要用程序来生成一个唯一的全局ID,然后在数据库事务中同时插入到多章表中实现同步.
在java中有个类工具很好的实现产生唯一ID(UUID),但是由数字和字母及中划线组成的,故数据库字段应该设置为char 并相应的建立索引.
UUID是128位整数(16字节)的全局唯一标识符(Universally Unique Identifier).
指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成UUID的API.UUID按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址,纳秒级时间,芯片ID码和许多可能的数字.由以下几部分的组合:当前日期和时间(UUID的第一个部分与时间有关,如果你在生成一个 UUID之后,过几秒又生成一个UUID,则第一个部分不同,其余相同),时钟序列,全局唯一的IEEE机器识别号(如果有网卡,从网卡获得,没有网卡以其他方式获得),UUID的唯一缺陷在于生成的结果串会比较长.关于UUID这个标准使用最普遍的是微软的GUID(Globals Unique Identifiers).
在ColdFusion中可以用CreateUUID()函数很简单的生成UUID,其格式为:xxxxxxxx- xxxx-xxxx-xxxxxxxxxxxxxxxx(8-4-4-16),其中每个 x 是 0-9 或 a-f 范围内的一个十六进制的数字.而标准的UUID格式为:xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12)
,可以从cflib 下载CreateGUID() UDF进行转换.
使用UUID的好处在分布式的软件系统中(比如:DCE/RPC, COM+,CORBA)就能体现出来,它能保证每个节点所生成的标识都不会重复,并且随着WEB服务等整合技术的发展,UUID的优势将更加明显.
关于UUID的更多信息可以多google 一下.
Java生成UUID
UUID(Universally Unique Identifier)全局唯一标识符,是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址,纳秒级时间,芯片ID码和许多可能的数字.由以下几部分的组合:当前日期和时间(UUID的第一个部分与时间有关,如果你在生成一个UUID之后,过几秒又生成一个UUID,则第一个部分不同,其余相同),时钟序列,全局唯一的IEEE机器识别号(如果有网卡,从网卡获得,没有网卡以其他方式获得),UUID的唯一缺陷在于生成的结果串会比较长.
在Java中生成UUID主要有以下几种方式:
JDK1.5
如果使用的JDK1.5的话,那么生成UUID变成了一件简单的事,以为JDK实现了UUID:
java.util.UUID, 直接调用即可.
UUID uuid = UUID.randomUUID();
String s = UUID.randomUUID().toString();//用来生成数据库的主键id非常不错..
Java代码 
package com.taobao.tddl.client.util;  
  
import java.io.IOException;  
import java.io.UnsupportedEncodingException;  
import java.net.InetAddress;  
import java.security.MessageDigest;  
import java.security.NoSuchAlgorithmException;  
import java.security.SecureRandom;  
import java.util.HashMap;  
import java.util.Map;  
import java.util.Random;  
import java.util.concurrent.atomic.AtomicLong;  
import java.util.concurrent.locks.ReentrantLock;  
  
/** 
 * @author huangshang 
 *  
 */  
public class UniqId {  
    private static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7',  
            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };  
  
    private static Map<Character, Integer> rDigits = new HashMap<Character, Integer>(  
            16);  
    static {  
        for (int i = 0; i < digits.length; ++i) {  
            rDigits.put(digits[i], i);  
        }  
    }  
  
    private static UniqId me = new UniqId();  
    private String hostAddr;  
    private Random random = new SecureRandom();  
    private MessageDigest mHasher;  
    private UniqTimer timer = new UniqTimer();  
  
    private ReentrantLock opLock = new ReentrantLock();  
  
    private UniqId() {  
        try {  
            InetAddress addr = InetAddress.getLocalHost();  
  
            hostAddr = addr.getHostAddress();  
        } catch (IOException e) {  
            hostAddr = String.valueOf(System.currentTimeMillis());  
        }  
  
        if (hostAddr == null || hostAddr.length() == 0  
                || "127.0.0.1".equals(hostAddr)) {  
            hostAddr = String.valueOf(System.currentTimeMillis());  
        }  
  
        try {  
            mHasher = MessageDigest.getInstance("MD5");  
        } catch (NoSuchAlgorithmException nex) {  
            mHasher = null;  
        }  
    }  
  
    /** 
     * 获取UniqID实例 
     *  
     * @return UniqId 
     */  
    public static UniqId getInstance() {  
        return me;  
    }  
  
    /** 
     * 获得不会重复的毫秒数 
     *  
     * @return 
     */  
    public long getUniqTime() {  
        return timer.getCurrentTime();  
    }  
  
    /** 
     * 获得UniqId 
     *  
     * @return uniqTime-randomNum-hostAddr-threadId 
     */  
    public String getUniqID() {  
        StringBuffer sb = new StringBuffer();  
        long t = timer.getCurrentTime();  
  
        sb.append(t);  
  
        sb.append("-");  
  
        sb.append(random.nextInt(8999) + 1000);  
  
        sb.append("-");  
        sb.append(hostAddr);  
  
        sb.append("-");  
        sb.append(Thread.currentThread().hashCode());  
  
        return sb.toString();  
    }  
  
    /** 
     * 获取MD5之后的uniqId string 
     *  
     * @return uniqId md5 string 
     */  
    public String getUniqIDHashString() {  
        return hashString(getUniqID());  
    }  
  
    /** 
     * 获取MD5之后的uniqId 
     *  
     * @return byte[16] 
     */  
    public byte[] getUniqIDHash() {  
        return hash(getUniqID());  
    }  
  
    /** 
     * 对字符串进行md5 
     *  
     * @param str 
     * @return md5 byte[16] 
     */  
    public byte[] hash(String str) {  
        opLock.lock();  
        try {  
            byte[] bt = mHasher.digest(str.getBytes("UTF-8"));  
            if (null == bt || bt.length != 16) {  
                throw new IllegalArgumentException("md5 need");  
            }  
            return bt;  
        } catch (UnsupportedEncodingException e) {  
            throw new RuntimeException("unsupported utf-8 encoding", e);  
        } finally {  
            opLock.unlock();  
        }  
    }  
  
    /** 
     * 对二进制数据进行md5 
     *  
     * @param str 
     * @return md5 byte[16] 
     */  
    public byte[] hash(byte[] data) {  
        opLock.lock();  
        try {  
            byte[] bt = mHasher.digest(data);  
            if (null == bt || bt.length != 16) {  
                throw new IllegalArgumentException("md5 need");  
            }  
            return bt;  
        } finally {  
            opLock.unlock();  
        }  
    }  
  
    /** 
     * 对字符串进行md5 string 
     *  
     * @param str 
     * @return md5 string 
     */  
    public String hashString(String str) {  
        byte[] bt = hash(str);  
        return bytes2string(bt);  
    }  
  
    /** 
     * 对字节流进行md5 string 
     *  
     * @param str 
     * @return md5 string 
     */  
    public String hashBytes(byte[] str) {  
        byte[] bt = hash(str);  
        return bytes2string(bt);  
    }  
  
    /** 
     * 将一个字节数组转化为可见的字符串 
     *  
     * @param bt 
     * @return 
     */  
    public String bytes2string(byte[] bt) {  
        int l = bt.length;  
  
        char[] out = new char[l << 1];  
  
        for (int i = 0, j = 0; i < l; i++) {  
            out[j++] = digits[(0xF0 & bt[i]) >>> 4];  
            out[j++] = digits[0x0F & bt[i]];  
        }  
  
        return new String(out);  
    }  
  
    /** 
     * 将字符串转换为bytes 
     *  
     * @param str 
     * @return byte[] 
     */  
    public byte[] string2bytes(String str) {  
        if (null == str) {  
            throw new NullPointerException("参数不能为空");  
        }  
        if (str.length() != 32) {  
            throw new IllegalArgumentException("字符串长度必须是32");  
        }  
        byte[] data = new byte[16];  
        char[] chs = str.toCharArray();  
        for (int i = 0; i < 16; ++i) {  
            int h = rDigits.get(chs[i * 2]).intValue();  
            int l = rDigits.get(chs[i * 2 + 1]).intValue();  
            data[i] = (byte) ((h & 0x0F) << 4 | (l & 0x0F));  
        }  
        return data;  
    }  
  
    /** 
     * 实现不重复的时间 
     *  
     * @author dogun 
     */  
    private static class UniqTimer {  
        private AtomicLong lastTime = new AtomicLong(System.currentTimeMillis());  
  
        public long getCurrentTime() {  
            return this.lastTime.incrementAndGet();  
        }  
    }  
}
4. java中如何将字符串转16位输出、、。例如“aa”,"0000 0000 0000 0000"按这样的方式输出
先要以正确的编码把字符串转为字节串,在把字节串转为16进制编码
public class Test {
	public static void main(String[] args) {		
		try{
			System.out.println(toHex("hello world","GBK"));
		}catch (UnsupportedEncodingException e){
			
			e.printStackTrace();
		}
	}
	static public String toHex(String text,String enc) throws UnsupportedEncodingException{
		byte B[]=text.getBytes(enc);
		StringBuilder buf=new StringBuilder(); 
		for(byte b:B){
			buf.append(Integer.toHexString(b&0xff));
		}
		return buf.toString();
	}
}
==========
68656c6c6f20776f726c64
5. 谁能提供一个java的纯数字加密的方法,要从8位变为16位,生成的加密数据要看起来没有规律
public class DesUtil {
 /** 字符串默认键值 */
 private static String strDefaultKey = "national";
 /** 加密工具 */
 private Cipher encryptCipher = null;
 /** 解密工具 */
 private Cipher decryptCipher = null;
 /**
  * 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[]
  * hexStr2ByteArr(String strIn) 互为可逆的转换过程
  *
  * @param arrB
  *            需要转换的byte数组
  * @return 转换后的字符串
  * @throws Exception
  *             本方法不处理任何异常,所有异常全部抛出
  */
 public static String byteArr2HexStr(byte[] arrB) throws Exception {
  int iLen = arrB.length;
  // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
  StringBuffer sb = new StringBuffer(iLen * 2);
  for (int i = 0; i < iLen; i++) {
   int intTmp = arrB[i];
   // 把负数转换为正数
   while (intTmp < 0) {
    intTmp = intTmp + 256;
   }
   // 小于0F的数需要在前面补0
   if (intTmp < 16) {
    sb.append("0");
   }
   sb.append(Integer.toString(intTmp, 16));
  }
  return sb.toString();
 }
 /**
  * 将表示16进制值的字符串转换为byte数组, 和public static String byteArr2HexStr(byte[] arrB)
  * 互为可逆的转换过程
  *
  * @param strIn
  *            需要转换的字符串
  * @return 转换后的byte数组
  * @throws Exception
  *             本方法不处理任何异常,所有异常全部抛出
  * @author <a href="mailto:[email protected]">LiGuoQing</a>
  */
 public static byte[] hexStr2ByteArr(String strIn) throws Exception {
  byte[] arrB = strIn.getBytes();
  int iLen = arrB.length;
  // 两个字符表示一个字节,所以字节数组长度是字符串长度除以2
  byte[] arrOut = new byte[iLen / 2];
  for (int i = 0; i < iLen; i = i + 2) {
   String strTmp = new String(arrB, i, 2);
   arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
  }
  return arrOut;
 }
 /**
  * 默认构造方法,使用默认密钥
  *
  * @throws Exception
  */
 public DesUtil() throws Exception {
  this(strDefaultKey);
 }
 /**
  * 指定密钥构造方法
  *
  * @param strKey
  *            指定的密钥
  * @throws Exception
  */
 public DesUtil(String strKey) throws Exception {
  Security.addProvider(new com.sun.crypto.provider.SunJCE());
  Key key = getKey(strKey.getBytes());
  encryptCipher = Cipher.getInstance("DES");
  encryptCipher.init(Cipher.ENCRYPT_MODE, key);
  decryptCipher = Cipher.getInstance("DES");
  decryptCipher.init(Cipher.DECRYPT_MODE, key);
 }
 /**
  * 加密字节数组
  *
  * @param arrB
  *            需加密的字节数组
  * @return 加密后的字节数组
  * @throws Exception
  */
 public byte[] encrypt(byte[] arrB) throws Exception {
  return encryptCipher.doFinal(arrB);
 }
 /**
  * 加密字符串
  *
  * @param strIn
  *            需加密的字符串
  * @return 加密后的字符串
  * @throws Exception
  */
 public String encrypt(String strIn) throws Exception {
  return byteArr2HexStr(encrypt(strIn.getBytes()));
 }
 /**
  * 解密字节数组
  *
  * @param arrB
  *            需解密的字节数组
  * @return 解密后的字节数组
  * @throws Exception
  */
 public byte[] decrypt(byte[] arrB) throws Exception {
  return decryptCipher.doFinal(arrB);
 }
 /**
  * 解密字符串
  *
  * @param strIn
  *            需解密的字符串
  * @return 解密后的字符串
  * @throws Exception
  */
 public String decrypt(String strIn) throws Exception {
  return new String(decrypt(hexStr2ByteArr(strIn)));
 }
 /**
  * 从指定字符串生成密钥,密钥所需的字节数组长度为8位 不足8位时后面补0,超出8位只取前8位
  *
  * @param arrBTmp
  *            构成该字符串的字节数组
  * @return 生成的密钥
  * @throws java.lang.Exception
  */
 private Key getKey(byte[] arrBTmp) throws Exception {
  // 创建一个空的8位字节数组(默认值为0)
  byte[] arrB = new byte[8];
  // 将原始字节数组转换为8位
  for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
   arrB[i] = arrBTmp[i];
  }
  // 生成密钥
  Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
  return key;
 }
 /**
  * main方法 。
  *
  * @author 刘尧兴
  * @param args
  */
 public static void main(String[] args) {
  try {
   String test = "asc";
   DesUtil des = new DesUtil("abc");// 自定义密钥
//   System.out.println("加密前的字符:" + test);
//   System.out.println("加密后的字符:" + des.encrypt(test));
//   System.out.println("解密后的字符:" + des.decrypt(des.encrypt(test)));
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}