-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
46 lines (29 loc) · 1.03 KB
/
README
File metadata and controls
46 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
bits operating classes
written by MATSUMOTO Eiji
from March 2, 2010
0. Basis
include file : Bits.h
namespace : emattsan::bits
1. Integer types of specified number of bits
Bits<4, signed> s; // signed 4 bit integer (-8..7)
Bits<4> u; // (or Bits<4, unsigned>) unsigned 4 bit integer (0..15)
s = 7; // s => 7
s = 8; // s => -8
s = 15; // s => -1
s = 16; // s => 0
u = 7; // u => 7
u = 8; // u => 8
u = 15; // u => 15
u = 16; // u => 0
2. Join
Bits<4, signed> s(1); // s => 1 ( 0001b )
BIts<4> u(8); // u => 8 ( 1000b )
int n = (s, u); // n => 24 ( 18h / 00011000b )
int n = (s, s, s); // n => 265 ( 111h / 000100010001b )
(s, n) = 0x5a; // s => 5, n = 10 ( 0ah )
3. Reserved bits
Bits<4, signed> s(1); // s => 1 ( 0001b )
Bits<4> u(8); // u => 8 ( 1000b )
int n = (s, reserve<2>, u); // n => 72 ( 048h / 0001001000b )
(s, reserve<2>, u) = 0xff; // s => 3 ( 0011b), (2 reserved bits discarded), u => 15 ( 1111b ),
<<EOF>>