8位无符号整数点分式版本

1、点分式版本

  版本 1.0.1.800 ,每个数字占用2个字节,一个8个字节组成8位无符号整数

  利用下面的脚本进行校验和转换

  

#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
__author__ = 'qqvipfunction'

import re

def versionToUInt64(version):
    version = version.strip()
    pattern = re.compile(r'^(\d+)\.(\d+)\.(\d+)\.(\d+)$')
    match = pattern.match(version)
    if match:
        uint16_max = 2<<16 - 1
        uint64_tuple = match.groups()
        value0 = int(uint64_tuple[0])
        value1 = int(uint64_tuple[1])
        value2 = int(uint64_tuple[2])
        value3 = int(uint64_tuple[3])
        if value0 <= uint16_max and value1 <= uint16_max and value2 <= uint16_max and value3 <= uint16_max:
            value = (value0<<48|value1<<32|value2<<16|value3)
            return str(value)
    return "invalid formate version"

if __name__ == '__main__':

    while True:
        version = input("version:")
        version = version.strip()
        print("version " + "\"" + version + "\" " + "to uint64 = " + versionToUInt64(version))

  

posted @ 2017-04-13 20:20  兜兜有糖的博客  阅读(471)  评论(0编辑  收藏  举报