package  fr.zng.xxzx.util;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.Charset;

public class ConvertUtil {

	/**
	 * 0000
	 */
	public static final String ZERO4 = "0000";

	public static void main(String[] arg) {

		/*System.out.println(StringUtil.padLeft(
				Integer.toHexString((new BigDecimal("88.88"))
						.multiply(new BigDecimal(100))
						.setScale(0, BigDecimal.ROUND_UP).intValue()), 8, '0'));
		System.out.println(hexStr2Str("c4e3bac3"));
		System.out.println(intToHexString(30000,4));*/
//		System.out.println(ConvertUtil.intToHexString(Integer.parseInt("80")*100, 4));
		
//		System.out.println(ConvertUtil.getCrcCode("e0004000027107"));
//		doMakeSerialList("aaaafae0000000105006000026dd000004edf1b5fae000000010500600002710000004f3f819dddd");
//		System.out.println(ConvertUtil.hexToStrMoney("002710"));
//		System.out.println(toStringHex111("cfb5cdb3bcecb2e2d6d0"));
		System.out.println(intToHexString(1,1));
	}
	
	public static String toStringHex111(String s) {  
		   byte[] baKeyword = new byte[s.length() / 2];  
		   for (int i = 0; i < baKeyword.length; i++) {  
		    try {  
		     baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(  
		       i * 2, i * 2 + 2), 16));  
		    } catch (Exception e) {  
		     e.printStackTrace();  
		    }  
		   }  
		   try {  
		    s = new String(baKeyword, "GBK");// UTF-16le:Not  
		   } catch (Exception e1) {  
		    e1.printStackTrace();  
		   }  
		   return s;  
		}

	/**
	 * 转码
	 * 
	 * @param data
	 * @return
	 */
	public static String asciiToHex(String data) {

		byte[] byteArr = data.getBytes(Charset.forName("GBK"));
		int[] inArr = new int[byteArr.length];
		String hex = "";
		for (int i = 0; i < byteArr.length; i++) {
			inArr[i] = byteArr[i] & 0xff;
			hex = hex + Integer.toHexString(byteArr[i] & 0xff);
		}

		return hex.toUpperCase();
	}

	public static String convertStringToHex2(String str) {

		char[] chars = str.toCharArray();

		StringBuffer hex = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			hex.append(Integer.toHexString(chars[i]));
		}

		return hex.toString();
	}

	public static String toFZDA(String data) {
		if (StringUtil.isEmpty(data) || (data.length() % 2 != 0)) {
			return "";
		}
		int i = 0;
		String ret = "";
		for (i = data.length(); i > 0; i = i - 2) {
			ret = ret + data.substring(i - 2, i);
		}
		return ret;
	}

	public static String tpCardMoney(String data) {
		if (StringUtil.isEmpty(data) || (data.length() % 2 != 0)) {
			return "";
		}
		int i = 0;
		String ret = "";
		for (i = data.length(); i > 0; i = i - 2) {
			ret = ret + data.substring(i - 2, i);
		}

		return ret;
	}

	public static String toStrMoney(String data) {
		//
		if (StringUtil.isEmpty(data)) {
			return "0000.00";
		}
		int in = data.indexOf(".");

		if (in < 0) {
			return StringUtil.padLeft(data, 4, '0') + ".00";
		} else {
			int sl = data.substring(in + 1).length();
			if (sl == 1) {
				return StringUtil.padLeft(data, 6, '0') + "0";
			} else {
				return StringUtil.padLeft(data, 7, '0');
			}
		}
	}

	/**
	 * 转化十六进制编码为字符串
	 * 
	 * @param s
	 * @return
	 */
	public static String toStringHex1(String s) {
		byte[] baKeyword = new byte[s.length() / 2];
		for (int i = 0; i < baKeyword.length; i++) {
			try {
				baKeyword[i] = (byte) (0xff & Integer.parseInt(
						s.substring(i * 2, i * 2 + 2), 16));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		try {
			s = new String(baKeyword, "utf-8");// UTF-16le:Not
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return s;
	}

	/**
	 * @Title:string2HexString
	 * @Description:字符串转16进制字符串
	 * @param strPart
	 *            字符串
	 * @return 16进制字符串
	 * @throws
	 */
	public static String string2HexString(String strPart) {
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < strPart.length(); i++) {
			int ch = strPart.charAt(i);
			String strHex = StringUtil.padLeft(Integer.toHexString(ch), 2, '0');
			hexString.append(strHex);
		}
		return hexString.toString();
	}

	public static String stringToAscii(String value) {
		StringBuffer sbu = new StringBuffer();
		char[] chars = value.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			if (i != chars.length - 1) {
				sbu.append((int) chars[i]).append("");
			} else {
				sbu.append((int) chars[i]);
			}
		}
		return sbu.toString();
	}

	/**
	 * @Title:hexString2String
	 * @Description:16进制字符串转字符串
	 * @param src
	 *            16进制字符串
	 * @return 字节数组
	 * @throws
	 */
	public static String hexString2String(String src) {
		String temp = "";
		for (int i = 0; i < src.length() / 2; i++) {
			temp = temp
					+ (char) Integer.valueOf(src.substring(i * 2, i * 2 + 2),
							16).byteValue();
		}

		return temp;
	}

	/**
	 * @Title:char2Byte
	 * @Description:字符转成字节数据char-->integer-->byte
	 * @param src
	 * @return
	 * @throws
	 */
	public static Byte char2Byte(Character src) {
		return Integer.valueOf(src).byteValue();
	}

	/**
	 * @Title:intToHexString
	 * @Description:10进制数字转成16进制
	 * @param a
	 *            转化数据
	 * @param len
	 *            占用字节数
	 * @return
	 * @throws
	 */
	public static String intToHexString(int a, int len) {
		len <<= 1;
		String hexString = Integer.toHexString(a);
		int b = len - hexString.length();
		if (b > 0) {
			for (int i = 0; i < b; i++) {
				hexString = "0" + hexString;
			}
		}
		return hexString;
	}

	/**
	 * @Title:bytes2HexString
	 * @Description:字节数组转16进制字符串
	 * @param b
	 *            字节数组
	 * @return 16进制字符串
	 * @throws
	 */
	public static String bytes2HexString(byte[] b) {
		StringBuffer result = new StringBuffer();
		String hex;
		for (int i = 0; i < b.length; i++) {
			hex = Integer.toHexString(b[i] & 0xFF);
			if (hex.length() == 1) {
				hex = '0' + hex;
			}
			result.append(hex.toUpperCase());
		}
		return result.toString();
	}

	/**
	 * @Title:hexString2Bytes
	 * @Description:16进制字符串转字节数组
	 * @param src
	 *            16进制字符串
	 * @return 字节数组
	 * @throws
	 */
	public static byte[] hexString2Bytes(String src) {
		int l = src.length() / 2;
		byte[] ret = new byte[l];
		for (int i = 0; i < l; i++) {
			ret[i] = Integer
					.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
		}
		return ret;
	}

	/**
	 * Convert byte[] to hex
	 * string.这里我们可以将byte转换成int，然后利用Integer.toHexString(int)来转换成16进制字符串。
	 * 
	 * @param src
	 *            byte[] data
	 * @return hex string
	 */
	public static String bytesToHexString(byte[] src) {
		StringBuilder stringBuilder = new StringBuilder("");
		if (src == null || src.length <= 0) {
			return null;
		}
		for (int i = 0; i < src.length; i++) {
			int v = src[i] & 0xFF;
			String hv = Integer.toHexString(v);
			if (hv.length() < 2) {
				stringBuilder.append(0);
			}
			stringBuilder.append(hv);
		}
		return stringBuilder.toString();
	}

	/**
	 * Convert byte[] to hex
	 * string.这里我们可以将byte转换成int，然后利用Integer.toHexString(int)来转换成16进制字符串。
	 * 
	 * @param src
	 *            byte[] data
	 * @return hex string
	 */
	public static String bytesToHexString(byte[] src, int len) {
		StringBuilder stringBuilder = new StringBuilder("");
		if (src == null || src.length <= 0) {
			return null;
		}
		for (int i = 0; i < len; i++) {
			int v = src[i] & 0xFF;
			String hv = Integer.toHexString(v);
			if (hv.length() < 2) {
				stringBuilder.append(0);
			}
			stringBuilder.append(hv);
		}
		return stringBuilder.toString();
	}

	/**
	 * 把16进制字符串转换成字节数组
	 * 
	 * @param hexString
	 * @return byte[]
	 */
	public static byte[] hexStringToByte(String hex) {
		int len = (hex.length() / 2);
		byte[] result = new byte[len];
		char[] achar = hex.toCharArray();
		for (int i = 0; i < len; i++) {
			int pos = i * 2;
			result[i] = (byte) (charToByte(achar[pos]) << 4 | charToByte(achar[pos + 1]));
		}
		return result;
	}

	/**
	 * Convert hex string to byte[]
	 * 
	 * @param hexString
	 *            the hex string
	 * @return byte[]
	 */
	public static byte[] hexStringToBytes(String hexString) {
		if (hexString == null || hexString.equals("")) {
			return null;
		}
		hexString = hexString.toUpperCase();
		int length = hexString.length() / 2;
		char[] hexChars = hexString.toCharArray();
		byte[] d = new byte[length];
		for (int i = 0; i < length; i++) {
			int pos = i * 2;
			d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
		}
		return d;
	}

	public static String convertStringToHex(String str) {

		char[] chars = str.toCharArray();

		StringBuffer hex = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			hex.append(Integer.toHexString(chars[i]));
		}

		return hex.toString();
	}

	/**
	 * 转化十六进制编码为字符串
	 * 
	 * @param s
	 * @return
	 */
	public static String toStringHex2(String s) {
		byte[] baKeyword = new byte[s.length() / 2];
		for (int i = 0; i < baKeyword.length; i++) {
			try {
				baKeyword[i] = (byte) (0xff & Integer.parseInt(
						s.substring(i * 2, i * 2 + 2), 16));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		try {
			s = new String(baKeyword, "utf-8");// UTF-16le:Not
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return s;
	}

	/**
	 * Convert char to byte
	 * 
	 * @param c
	 *            char
	 * @return byte
	 */
	private static byte charToByte(char c) {
		return (byte) "0123456789ABCDEF".indexOf(c);
	}

	public final static char[] BToA = "0123456789abcdef".toCharArray();

	public static byte[] asciiToBcd(byte[] ascii, int asc_len) {
		byte[] bcd = new byte[asc_len / 2];
		int j = 0;
		for (int i = 0; i < (asc_len + 1) / 2; i++) {
			bcd[i] = ascToBcd(ascii[j++]);
			bcd[i] = (byte) (((j >= asc_len) ? 0x00 : ascToBcd(ascii[j++])) + (bcd[i] << 4));
		}
		return bcd;
	}

	private static byte ascToBcd(byte asc) {
		byte bcd;

		if ((asc >= '0') && (asc <= '9'))
			bcd = (byte) (asc - '0');
		else if ((asc >= 'A') && (asc <= 'F'))
			bcd = (byte) (asc - 'A' + 10);
		else if ((asc >= 'a') && (asc <= 'f'))
			bcd = (byte) (asc - 'a' + 10);
		else
			bcd = (byte) (asc - 48);
		return bcd;
	}

	/**
	 * @函数功能: BCD码转ASC码
	 * @输入参数: BCD串
	 * @输出结果: ASC码
	 */
	public static String bcd2Asc(byte[] bytes) {
		StringBuffer temp = new StringBuffer(bytes.length * 2);

		for (int i = 0; i < bytes.length; i++) {
			int h = ((bytes[i] & 0xf0) >>> 4);
			int l = (bytes[i] & 0x0f);
			temp.append(BToA[h]).append(BToA[l]);
		}
		return temp.toString();
	}

	public static short getShort(byte[] bytes) {
		return (short) ((0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)));
	}

	public static int getInt(byte[] bytes) {
		return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8))
				| (0xff0000 & (bytes[2] << 16))
				| (0xff000000 & (bytes[3] << 24));
	}

	/**
	 * @功能: BCD码转为10进制串(阿拉伯数据)
	 * @参数: BCD码
	 * @结果: 10进制串
	 */
	public static String bcd2Str(byte[] bytes) {
		StringBuffer temp = new StringBuffer(bytes.length * 2);
		for (int i = 0; i < bytes.length; i++) {
			temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
			temp.append((byte) (bytes[i] & 0x0f));
		}
		return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp
				.toString().substring(1) : temp.toString();
	}

	/**
	 * 16进制转10进制    金额0000.00
	 * @param data
	 * @return
	 */
	public static String hexToStrMoney(String data) {
		return BigDecimal.valueOf(Long.valueOf(data, 16))
				.divide(new BigDecimal("100")).setScale(2).toString();
	}
	/**
	 * @功能: 10进制串转为BCD码
	 * @参数: 10进制串
	 * @结果: BCD码
	 */
	public static byte[] str2Bcd(String asc) {
		int len = asc.length();
		int mod = len % 2;
		if (mod != 0) {
			asc = "0" + asc;
			len = asc.length();
		}
		byte abt[] = new byte[len];
		if (len >= 2) {
			len = len / 2;
		}
		byte bbt[] = new byte[len];
		abt = asc.getBytes();
		int j, k;
		for (int p = 0; p < asc.length() / 2; p++) {
			if ((abt[2 * p] >= '0') && (abt[2 * p] <= '9')) {
				j = abt[2 * p] - '0';
			} else if ((abt[2 * p] >= 'a') && (abt[2 * p] <= 'z')) {
				j = abt[2 * p] - 'a' + 0x0a;
			} else {
				j = abt[2 * p] - 'A' + 0x0a;
			}
			if ((abt[2 * p + 1] >= '0') && (abt[2 * p + 1] <= '9')) {
				k = abt[2 * p + 1] - '0';
			} else if ((abt[2 * p + 1] >= 'a') && (abt[2 * p + 1] <= 'z')) {
				k = abt[2 * p + 1] - 'a' + 0x0a;
			} else {
				k = abt[2 * p + 1] - 'A' + 0x0a;
			}
			int a = (j << 4) + k;
			byte b = (byte) a;
			bbt[p] = b;
		}
		return bbt;
	}

	// 转化十六进制编码为字符串
	public static String toStringHex3(String s) {
		byte[] baKeyword = new byte[s.length() / 2];
		for (int i = 0; i < baKeyword.length; i++) {
			try {
				baKeyword[i] = (byte) (Integer.parseInt(
						s.substring(i * 2, i * 2 + 2), 16));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		try {
			s = new String(baKeyword, "utf-8");// UTF-16le:Not
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return s;
	}
	
	/**
	 * 十六进制转换字符串
	 * 
	 * @param String
	 *            str Byte字符串(Byte之间无分隔符 如:[616C6B])
	 * @return String 对应的字符串
	 */
	public static String hexStr2Str(String hexStr) {
		String str = "0123456789ABCDEF";
		char[] hexs = hexStr.toUpperCase().toCharArray();
		byte[] bytes = new byte[hexStr.length() / 2];
		int n;

		for (int i = 0; i < bytes.length; i++) {
			n = str.indexOf(hexs[2 * i]) * 16;
			n += str.indexOf(hexs[2 * i + 1]);
			bytes[i] = (byte) (n & 0xff);
		}
		try {
			return new String(bytes, "GB2312");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static String HexToAsciiString(String hex) {

		StringBuilder sb = new StringBuilder();

		// 49204c6f7665204a617661 split into two characters 49, 20, 4c...
		for (int i = 0; i < hex.length() - 1; i += 2) {

			// grab the hex in pairs
			String output = hex.substring(i, (i + 2));
			// convert hex to decimal
			int decimal = Integer.parseInt(output, 16);
			// convert the decimal to character
			sb.append((char) decimal);

		}
		return sb.toString();
	}

	public static byte[] HexStrToAscii(String InString) {
		int i = 0;
		byte[] by = new byte[InString.length() / 2];
		byte temp = 0;
		int loop = 0;
		// 字符转为byte
		while (true) {
			temp = (byte) Integer.parseInt(InString.substring(i, i + 2), 16);
			//
			by[loop] = temp;
			i = i + 2;
			loop++;
			if (i >= InString.length()) {
				break;
			}

		}

		return by;
	}

	// 601234567860210000000008200000000000c00010
	// 451230124512301200000210301
	// 00526012345678602100 00000008200000000000C00010
	// 34353132333031323132333435363738393031323334350011000002103010
	/**
	 * 位图中的 2进制字符串 转hex 字符串
	 * 
	 * @param 2进制字符串
	 * @return
	 */
	public static String binaryString2hexString(String binaryString) {
		if (binaryString == null || binaryString.length() % 2 != 0)
			return null;
		String hexString = "", tmp;
		for (int i = 0; i < binaryString.length() / 4; i++) {
			tmp = Integer.toHexString(Integer.parseInt(
					binaryString.substring(i * 4, (i + 1) * 4), 2));
			hexString += tmp.substring(tmp.length() - 1);
		}
		return hexString;
	}

	public static String convertAsciiToHex(String str) {

		char[] chars = str.toCharArray();

		StringBuffer hex = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			hex.append(Integer.toHexString(chars[i]));
		}

		return hex.toString();
	}

	/**
	 * 字符串的长度不足，补0固定字长
	 * 
	 * @param str
	 *            字符串
	 * @param strLength
	 *            字符串固定长度
	 * @param left
	 *            true左补0，false右补0
	 * @return
	 */
	public static String addZeroForNum(String str, int strLength, boolean left) {
		int strLen = str.length();
		StringBuffer sb = null;
		while (strLen < strLength) {
			sb = new StringBuffer();
			if (left) {
				sb.append("0").append(str); // 左补0
			} else {
				sb.append(str).append("0");// 右补0
			}
			str = sb.toString();
			strLen = str.length();
		}
		return str;
	}

	/**
	 * 类型格式化 被转换数据16进制
	 * 
	 * @param type
	 * @param data
	 *            16进制
	 * @return
	 */
	public static String formatData(String type, String data) {

		if ("BCD".equals(type)) {
			return data;
		} else if ("ASCII".equals(type)) {
			return ConvertUtil.toStringHex3(data);
		} else if ("BINARY".equals(type)) {
			return hexString2binaryString(data);
		} else {
			return data;
		}
	}

	/**
	 * 类型格式化 返回数据为16进制
	 * 
	 * @param type
	 *            被转换的数据类型
	 * @param data
	 *            被转换的数据
	 * @return
	 */
	public static String formatToHexData(String type, String data) {

		if ("BCD".equals(type)) {
			return data;
		} else if ("ASCII".equals(type)) {
			return ConvertUtil.string2HexString(data);
		} else if ("BINARY".equals(type)) {
			return binaryString2hexString(data);
		} else {
			return data;
		}
	}

	/**
	 * hex字符串 转2进制字符串
	 * 
	 * @param hexString
	 * @return
	 */
	public static String hexString2binaryString(String hexString) {
		if (hexString == null || hexString.length() % 2 != 0)
			return null;
		String bString = "", tmp;
		for (int i = 0; i < hexString.length(); i++) {
			tmp = ZERO4
					+ Integer.toBinaryString(Integer.parseInt(
							hexString.substring(i, i + 1), 16));
			bString += tmp.substring(tmp.length() - 4);
		}
		return bString;
	}

	/**
	 * 
	 * @param data
	 */
	public static String doHexToIntStr(String tmp) {
		return String.valueOf(Integer.parseInt(tmp, 16));
	}

	/**
	 * 获取CRCCode 高字节在前低字节在后
	 * @param str 字符窜
	 * @return 校验值
	 */
	public static String getCrcCode(String str) {
		str = str.replace(" ", "");
		long lon = GetModBusCRC(str.replace(" ", ""));
		int h1, l0;
		l0 = (int) lon / 256;
		h1 = (int) lon % 256;
		String s = "";
		if (Integer.toHexString(h1).length() < 2) {
			s = "0" + Integer.toHexString(h1);
		} else {
			s = Integer.toHexString(h1);
		}
		if (Integer.toHexString(l0).length() < 2) {
			s = s + "0" + Integer.toHexString(l0);
		} else {
			s = s + Integer.toHexString(l0);
		}
		s = ConvertUtil.toFZDA(s);
		return s;
	}


	/**
	 * 检测Crc
	 * @param recData
	 * @return
	 */
	public static boolean checkCrcCode(String recData) {
		recData = recData.replace(" ", "");
		int len = recData.length();
		String str = recData.substring(2, len - 4);
		long lon = GetModBusCRC(str.replace(" ", ""));
		int h1, l0;
		l0 = (int) lon / 256;
		h1 = (int) lon % 256;
		String s = "";
		if (Integer.toHexString(h1).length() < 2) {
			s = "0" + Integer.toHexString(h1);
		} else {
			s = Integer.toHexString(h1);
		}
		if (Integer.toHexString(l0).length() < 2) {
			s = s + "0" + Integer.toHexString(l0);
		} else {
			s = s + Integer.toHexString(l0);
		}

		if (Integer.parseInt(ConvertUtil.toFZDA(s), 16) == Integer.parseInt(
				recData.substring(len - 4, len), 16)) {
			return true;
		}
		return false;
	}

	/**
	 * 转字符串
	 * @param hexString
	 * @return
	 */
	public static int[] strToToHexByte(String hexString) {
		hexString = hexString.replace(" ", "");

		if ((hexString.length() % 2) != 0) {
			hexString += " ";
		}

		int[] returnBytes = new int[hexString.length() / 2];

		for (int i = 0; i < returnBytes.length; i++)
			returnBytes[i] = (0xff & Integer.parseInt(
					hexString.substring(i * 2, i * 2 + 2), 16));
		return returnBytes;
	}

	/**
	 * 获取CRC校验
	 * @param DATA
	 * @return
	 */
	public static long GetModBusCRC(String DATA) {
		long functionReturnValue = 0;
		long i = 0;

		long J = 0;
		int[] v = null;
		byte[] d = null;
		v = strToToHexByte(DATA);

		long CRC = 0;
		CRC = 0x0000L;
		for (i = 0; i <= (v).length - 1; i++) {
			CRC = (CRC / 256) * 256L + (CRC % 256L) ^ v[(int) i];
			for (J = 0; J <= 7; J++) {

				long d0 = 0;
				d0 = CRC & 1L;
				CRC = CRC / 2;
				if (d0 == 1)
					CRC = CRC ^ 0xa001L;
			}
		}
		CRC = CRC % 65536;
		functionReturnValue = CRC;
		return functionReturnValue;
	}

//	public static void doMakeDataMapList(String data) {
//		
//		String[] str = data.split("fae000");
//		List<String> list=new ArrayList<String>();
//		String tmp = "";
//        for(String s:str){
//        	
//        	tmp = "fae000" + s;
//        	System.out.println(tmp);
//        	list.add(tmp);
//        }
//		
//	}

	/**
	 * 连续两个fa重复合并为一个fa
	 * 
	 * @param data
	 *            原数据字符串
	 * @return newData 合并后的数据字符串
	 */
	public static String getNewData(String data) {
		String uptmp = "";
		String tmp = "";
		String ret = "";
		for (int i = 0; i < data.length(); i = i + 2) {
			if (i == 0) {
				uptmp = data.substring(i, i + 2);
				ret = ret + uptmp;
				//uptmp = "";
			} else {
				tmp = data.substring(i, i + 2);

				if ("fa".equals(tmp) && "fa".equals(uptmp)) {
					uptmp = "";
					continue;
				} else {
					uptmp = tmp;
					ret = ret + tmp;
				}
			}

		}
		return ret;
	}
	
}
