nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
base_conversions.hpp
Go to the documentation of this file.
1
3// toolboxes/comm/include/nk/comm/source/base_conversions.hpp
4//
5// Communications Toolbox base-conversion utilities: bit <-> integer
6// packing (bit2int / int2bit) and the legacy binary <-> decimal digit
7// converters (bi2de / de2bi), plus the vec2mat reshape-with-padding helper.
8
9#pragma once
10
11#include <memory_resource>
12#include <utility>
13#include <nk/value/value.hpp>
14
15namespace nk::comm {
16
19
20
34Value bit2int(const Value &b, int n, bool msbfirst = true,
35 std::pmr::memory_resource *mr = nullptr);
36
50Value int2bit(const Value &d, int n, bool msbfirst = true,
51 std::pmr::memory_resource *mr = nullptr);
52
68Value bi2de(const Value &b, int base = 2, bool msbfirst = false,
69 std::pmr::memory_resource *mr = nullptr);
70
87Value de2bi(const Value &d, int n = -1, int base = 2, bool msbfirst = false,
88 std::pmr::memory_resource *mr = nullptr);
89
105std::pair<Value, int>
106vec2mat(const Value &v, int n, double padval = 0.0,
107 std::pmr::memory_resource *mr = nullptr);
108
109
111} // namespace nk::comm
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
Value bi2de(const Value &b, int base=2, bool msbfirst=false, std::pmr::memory_resource *mr=nullptr)
Convert digit-rows to decimal — d = bi2de(b) (legacy).
Value de2bi(const Value &d, int n=-1, int base=2, bool msbfirst=false, std::pmr::memory_resource *mr=nullptr)
Convert integers to digit-rows — b = de2bi(d) (legacy).
Value bit2int(const Value &b, int n, bool msbfirst=true, std::pmr::memory_resource *mr=nullptr)
Pack a bit vector into integers — y = bit2int(b, n).
std::pair< Value, int > vec2mat(const Value &v, int n, double padval=0.0, std::pmr::memory_resource *mr=nullptr)
Reshape a vector into an N-column matrix with padding — [m, pad] = vec2mat(v, n).
Value int2bit(const Value &d, int n, bool msbfirst=true, std::pmr::memory_resource *mr=nullptr)
Unpack integers into a bit matrix — b = int2bit(d, n).