1 // This file is part of the ustl library, an STL implementation.
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
13 /// Copies bits from \p v of size \p n into \p buf as MSB "1011001..." LSB
14 /// If \p buf is too small, MSB bits will be truncated.
15 void convert_to_bitstring (const bitset_value_type
* v
, size_t n
, string
& buf
)
17 string::iterator stri
= buf
.end();
18 for (size_t i
= 0; i
< n
&& stri
> buf
.begin(); ++ i
)
19 for (bitset_value_type b
= 1; b
&& stri
> buf
.begin(); b
<<= 1)
20 *--stri
= (v
[i
] & b
) ? '1' : '0';
23 /// Copies bits from \p buf as MSB "1011001..." LSB into \p v of size \p n.
24 void convert_from_bitstring (const string
& buf
, bitset_value_type
* v
, size_t n
)
26 string::const_iterator stri
= buf
.end();
27 for (size_t i
= 0; i
< n
; ++ i
) {
28 for (bitset_value_type b
= 1; b
; b
<<= 1) {
29 if (stri
== buf
.begin() || *--stri
== '0')