- or download this
|<--------- 16-bit config register ---------->|
| | |
...
START | | UNUSED DATA
CHANNEL |
PIN SELECT
- or download this
15: Start conversation
0 - do nothing
...
10-8: Unused (Don't care bits)
7-0: Data
- or download this
my $data = bit_on(0, 15);
- or download this
say bit_count($data);
say bit_bin($data);
- or download this
16
1000000000000000
- or download this
# setting channel
$data = bit_set($data, 13, 2, 0b11);
# result: 1110000000000000
- or download this
# setting pin
$data = bit_set($data, 11, 2, 0b01);
# result: 1110100000000000
- or download this
# setting data
...
# or: bit_set($data, 0, 8, 0b10111010);
# result: 1110100010111010
- or download this
$data = bit_off($data, 14);
# result: 1010100010111010
- or download this
my $value = bit_get($data, 15, 15);
say bit_bin($value);
# result: 1
- or download this
# data
...
# ensure the unused bits weren't set
say bit_get($data, 10, 8);
- or download this
# use a binary number directly:
...
# convert a number to a binary string, and assign it
my $bin = sprintf("%b", 127); # 1111111