📄 converter.java
字号:
public class Converter {
static final String ENCODING = "UTF-8";
static void packInt(byte[] arr, int offs, int x) {
arr[offs] = (byte)(x >> 24);
arr[offs+1] = (byte)(x >> 16);
arr[offs+2] = (byte)(x >> 8);
arr[offs+3] = (byte)x;
}
static int unpackInt(byte[] arr, int offs) {
return (arr[offs] << 24) | ((arr[offs+1] & 0xFF) << 16) | ((arr[offs+2] & 0xFF) << 8) | (arr[offs+3] & 0xFF);
}
static void packLong(byte[] arr, int offs, long x) {
packInt(arr, offs, (int)(x >> 32));
packInt(arr, offs+4, (int)x);
}
static long unpackLong(byte[] arr, int offs) {
return ((long)unpackInt(arr, offs) << 32) | (unpackInt(arr, offs+4) & 0xFFFFFFFFL);
}
static byte[] packString(String str) {
try {
return str.getBytes(ENCODING);
} catch (java.io.UnsupportedEncodingException x) {
return str.getBytes();
}
}
static String unpackString(byte[] arr, int offs, int len) {
try {
return new String(arr, offs, len, ENCODING);
} catch (java.io.UnsupportedEncodingException x) {
return new String(arr, offs, len);
}
}
static void twoDigits(StringBuffer buf, int val) {
buf.append((char)('0' + val / 10));
buf.append((char)('0' + val % 10));
}
static String timeToString(int time) {
StringBuffer buf = new StringBuffer();
int seconds = time % 60;
int minutes = time / 60 % 60;
int hours = time / 3600 % 24;
int days = time / (3600*24);
if (days != 0) {
buf.append(days);
buf.append(' ');
twoDigits(buf, hours);
buf.append(':');
twoDigits(buf, minutes);
} else {
twoDigits(buf, hours);
buf.append(':');
twoDigits(buf, minutes);
buf.append(':');
twoDigits(buf, seconds);
}
return buf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -