123456789101112131415161718192021222324252627282930313233343536 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- def a_bit(data, i):
- if i == 1:
- return data & 0x01
- if i == 2:
- return (data & 0x02) >> 1
- if i == 3:
- return (data & 0x04) >> 2
- if i == 4:
- return (data & 0x08) >> 3
- if i == 5:
- return (data & 0x10) >> 4
- if i == 6:
- return (data & 0x20) >> 5
- if i == 7:
- return (data & 0x40) >> 6
- if i == 8:
- return (data & 0x80) >> 7
- def hex_bcd(data):
- s = data // 16
- g = data % 16
- c = s * 10 + g
- return str(c)
- def bcd_hex(data):
- int_data = int(data)
- s = int_data // 10
- g = int_data % 10
- c = s * 16 + g
- return c
|