Skip to content

Instantly share code, notes, and snippets.

@luqinghui
luqinghui / date.java
Last active September 30, 2016 08:21
public class Date_My {
private final int value;
public Date_My(int year, int month, int day){
value = year*512 + month*32 + day;
// value = y * 2^9 + m * 2^5+ d;
}
public int month(){
return (value / 32) % 16;
// 除以32后,剩下 y*2^4 + m(d消掉了,2^4 = 2^9 / 2^5),接着再用16(即2^4)取余,得month
}