FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-lib/src/bit.cpp at master · dst/cpp-lib · GitHub
dst
cpp-lib
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-lib
/
src
/
bit.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (31 loc) · 754 Bytes
Breadcrumbs
cpp-lib
/
src
/
bit.cpp
Copy path
File metadata and controls
37 lines (31 loc) · 754 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* bitlib.cpp
*
* Created on: Nov 2, 2013
* Author: dst
*/
#
include
<
bitset
>
#
include
<
cassert
>
#
include
<
cmath
>
#
include
<
iostream
>
using
namespace
std
;
using
std::bitset;
inline
void
bit
() {
//
bitset
bitset<
10
> empty;
assert
(empty[
0
] ==
false
);
assert
(empty[
9
] ==
false
);
//
initialize from string
bitset<
10
>
second
(
"
01011
"
);
//
second is 0000001011
assert
(second.
to_ulong
() ==
11
);
//
bitset stores bits in reverse order
bitset<
4
> bits;
//
0000
assert
(bits.
to_ulong
() ==
0
);
bits[
1
]=
1
;
//
0010
assert
(bits.
to_ulong
() ==
2
);
bits[
2
]=
1
;
//
0110
assert
(bits.
to_ulong
() ==
6
);
//
bit operations
assert
(
1
<<
20
==
1024
*
1024
);
}
Back
|
FazBrowse Home
|
New Git URL