因此,我们有一家软件供应商,该供应商已将时间存储在CHAR(216)字段的数据库中。在GUI中,您可以选择门的开放时间,以15分钟为增量。因此,在下面的示例中,营业时间为周一至周五上午8点至下午5点开放。所以有趣的部分。对于下面的示例,这是时间位在SQL中的存储方式。据我所知,数据是从星期日到星期六按顺序存储的。有人对我如何将其转换为实际的日期和时间有任何想法吗?
周一至周五8 AM-5PM:00000000000000000000000000000000000000FFFFFFFF0F00000000000000FFFFFFFF0F00000000000000FFFFFFFF0F00000000000000FFFFFFFF0F00000000000000FFFFFFFF0F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
全部关闭: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
全部开放: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
答案 0 :(得分:2)
计算流中每个i
位的索引1
。 i*15
是自本周开始(星期日,00:00?)以来的分钟数,因此您可以将该分钟数加到本周的开始时间,并获得开始间隔的时间点。
很明显,数据首先以LSB字节表示。请注意,每个十六进制字符代表4位,即一个小时。
您可以遍历字符串,一次提取两个十六进制字符,转换为整数,然后找到位集,同时为每个处理的位增加索引i
。
伪代码:
byte currentByte;
for ( int bitIndex = 0; bitIndex < (216*4); bitIndex++ ) {
if ( bitIndex % 8 == 0 ) {
/* Need to fetch next byte from the bit-map */
int stringIndex = bitIndex / 4; /* 4 bits make up one character */
String hexByte = substring( input, stringIndex, stringIndex + 2); /* get next two hex characters */
currentByte = parse_hex( hexByte );
}
if ( (currentByte & 1) != 0 ) {
/* Lowest bit is set -> open! */
output( "Open starting at " + (bitIndex * 15) + " minutes from the start of the week.");
} else {
/* Lowest bit not set -> closed! */
}
currentByte = currentByte / 2; /* logical shift right by 1 bit */
}