Commit 683b01807250481e0874c533b6018c81420e3ff5

[WiP] readjusting the itoc function. Needs to be itoa really, and I
should check my stdlib headers to see if it's already there.

Commit diff

bits.hpp

 
44////////////////////////////////////////////////////////////////
55#ifndef _SHA_BITS_HPP_
66#define _SHA_BITS_HPP_
7
87#include <algorithm>
98#include <boost/dynamic_bitset.hpp>
109
2121 }
2222 }
2323
24 inline const char itoc(unsigned int n, int radix)
24 inline const char* itoc(unsigned int n, int radix)
2525 {
26 char digits[8] = {0};
27 unsigned int tmp = 0;
28 int i =0;
29
30 while (n >= radix)
31 {
32 tmp = n / radix;
33 n -= tmp;
34
35 }
2636 unsigned char n0 = n % radix;
2737 unsigned char n1 = n / radix;
2838
29 return (n1 << 4 | n0);
39
3040 }
3141}
3242
toggle raw diff

sha.hpp

 
4747
4848 for (int i=0; i<num_bytes; ++i)
4949 {
50 result.push_back(bits::itoc(((data>>(i*8)) & lsb_mask).to_ulong(), base));
50 char c = bits::itoc(((data>>(i*8)) & lsb_mask).to_ulong(), base);
51 result.push_back(c);
5152 }
5253
5354 bits::reverse_bytes(result.begin(), result.end());
toggle raw diff

test0.cpp

 
33// \date January 2008
44////////////////////////////////////////////////////////////////
55#include "sha.hpp"
6#include <bitset>
67#include <iostream>
78#include <string>
89
910int main()
1011{
11 sha1_t hash0(std::string("hello"));
12 std::bitset<8> testbs(std::string("10101010"));
1213
13 std::cout << hash0 << std::endl;
14 std::cout << to_string(testbs, 16) << std::endl;
1415}
toggle raw diff