将2612转换成时间和周一到周日

<pre class="html" name="code">public class ByteUtil {

	public static byte[] intToByteArray(int num, int size) {
		byte[] temp = new byte[size];
		for (int i = 0; i < size; i++) {
			temp[i] = (byte) ((num >> 8 * i) & 0xFF);
		}
		return temp;
	}

	public static byte[] intToByte(int i) {

		byte[] abyte0 = new byte[4];

		abyte0[0] = (byte) (0xff & i);

		abyte0[1] = (byte) ((0xff00 & i) >> 8);

		abyte0[2] = (byte) ((0xff0000 & i) >> 16);

		abyte0[3] = (byte) ((0xff000000 & i) >> 24);

		return abyte0;

	}

	public static int bytesToInt(byte[] bytes) {

		int addr = 0;

		try {
			addr = bytes[0] & 0xFF;

			addr |= ((bytes[1] << 8) & 0xFF00);

			addr |= ((bytes[2] << 16) & 0xFF0000);

			addr |= ((bytes[3] << 24) & 0xFF000000);

		} catch (Exception e) {

		}

		return addr;

	}

	/**
	 * 1 + 2 + 4 + 8 + 16 + 32 + 64
	 * 
	 * @param cycle
	 */
	public static String convertToDay(int cycle) {
		String[] days = { "周日", "周六", "周五", "周四", "周三", "周二", "周一" };
		cycle = cycle < 128 ? cycle + 128 : cycle;
		if (cycle == 128) {
			return "永不";
		}
		if (cycle == 255) {
			return "每天(周一 周二 周三 周四 周五 周六 周日)";
		}
		char[] c = Integer.toBinaryString(cycle).toCharArray();
		StringBuilder builder = new StringBuilder();
		for (int i = c.length - 1; i > 0; i--) {
			if (String.valueOf(c[i]).equals("1")) {
				builder.append(days[i - 1] + " ");
			}
		}
		return builder.toString();
	}

}

byte[] time = ByteUtil.intToByte(bean.Time);String hour = time[1] < 10 ? "0" + time[1] : "" + time[1];String minute = time[0] < 10 ? "0" + time[0] : "" + time[0];tvAlarmTime.setText(getString(R.string.vibrate_time, hour, minute));
 

	public static byte[] intToByte(int i) {

		byte[] abyte0 = new byte[4];

		abyte0[0] = (byte) (0xff & i);

		abyte0[1] = (byte) ((0xff00 & i) >> 8);

		abyte0[2] = (byte) ((0xff0000 & i) >> 16);

		abyte0[3] = (byte) ((0xff000000 & i) >> 24);

		return abyte0;

	}

int cycle = bean.Cycle;
			cycle = cycle < 128 ? cycle + 128 : cycle;
			char[] c = Integer.toBinaryString(cycle).toCharArray();
			cbMonday.setChecked(String.valueOf(c[7]).equals("1"));
			cbTuesday.setChecked(String.valueOf(c[6]).equals("1"));
			cbWednesday.setChecked(String.valueOf(c[5]).equals("1"));
			cbThursday.setChecked(String.valueOf(c[4]).equals("1"));
			cbFriday.setChecked(String.valueOf(c[3]).equals("1"));
			cbSaturday.setChecked(String.valueOf(c[2]).equals("1"));
			cbSunday.setChecked(String.valueOf(c[1]).equals("1"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值