Hush Full Node software. We were censored from Github, this is where all development happens now. https://hush.is
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.3 KiB

// Copyright (c) 2019-2020 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "zcash/util.h"
#include <algorithm>
#include <stdexcept>
std::vector<unsigned char> convertIntToVectorLE(const uint64_t val_int) {
std::vector<unsigned char> bytes;
for(size_t i = 0; i < 8; i++) {
bytes.push_back(val_int >> (i * 8));
}
return bytes;
}
// Convert bytes into boolean vector. (MSB to LSB)
std::vector<bool> convertBytesVectorToVector(const std::vector<unsigned char>& bytes) {
std::vector<bool> ret;
ret.resize(bytes.size() * 8);
unsigned char c;
for (size_t i = 0; i < bytes.size(); i++) {
c = bytes.at(i);
for (size_t j = 0; j < 8; j++) {
ret.at((i*8)+j) = (c >> (7-j)) & 1;
}
}
return ret;
}
// Convert boolean vector (big endian) to integer
uint64_t convertVectorToInt(const std::vector<bool>& v) {
if (v.size() > 64) {
throw std::length_error ("boolean vector can't be larger than 64 bits");
}
uint64_t result = 0;
for (size_t i=0; i<v.size();i++) {
if (v.at(i)) {
result |= (uint64_t)1 << ((v.size() - 1) - i);
}
}
return result;
}