OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [src/] [ubitset.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#include "ubitset.h"
7
 
8
namespace ustl {
9
 
10
/// Copies bits from \p v of size \p n into \p buf as MSB "1011001..." LSB
11
/// If \p buf is too small, MSB bits will be truncated.
12
void convert_to_bitstring (const bitset_value_type* v, size_t n, string& buf)
13
{
14
    string::iterator stri = buf.end();
15
    for (size_t i = 0; i < n && stri > buf.begin(); ++ i)
16
        for (bitset_value_type b = 1; b && stri > buf.begin(); b <<= 1)
17
            *--stri = (v[i] & b) ? '1' : '0';
18
}
19
 
20
/// Copies bits from \p buf as MSB "1011001..." LSB into \p v of size \p n.
21
void convert_from_bitstring (const string& buf, bitset_value_type* v, size_t n)
22
{
23
    string::const_iterator stri = buf.end();
24
    for (size_t i = 0; i < n; ++ i) {
25
        for (bitset_value_type b = 1; b; b <<= 1) {
26
            if (stri == buf.begin() || *--stri == '0')
27
                v[i] &= ~b;
28
            else
29
                v[i] |= b;
30
        }
31
    }
32
}
33
 
34
} // namespace ustl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.