From 99ab093c910f1fdddfb7328f3ea8e9fff484e928 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 3 Oct 2005 07:06:28 +0000 Subject: [PATCH] Salida en hexa. --- src/number.h | 15 +++++++++++++-- tests/number.cpp | 10 ++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/number.h b/src/number.h index 4b77f22..7df04e1 100644 --- a/src/number.h +++ b/src/number.h @@ -7,12 +7,17 @@ #include #include #include -#include #include /* sizeof(E) tiene que ser 2*sizeof(N); y son los tipos nativos con los cuales * se haran las operaciones mas basicas. */ +template < typename N, typename E > +struct number; + +template < typename N, typename E > +std::ostream& operator<< (std::ostream& os, const number< N, E >& n); + template < typename N = uint32_t, typename E = uint64_t > struct number { @@ -76,6 +81,10 @@ struct number const_reverse_iterator rbegin() const { return chunk.rbegin(); } const_reverse_iterator rend() const { return chunk.rend(); } + // Friends + template < typename NN, typename EE > + friend std::ostream& operator<< (std::ostream& os, const number< NN, EE>& n); + private: // Atributos chunk_type chunk; @@ -206,7 +215,9 @@ template < typename N, typename E > std::ostream& operator<< (std::ostream& os, const number< N, E >& n) { // FIXME sacar una salida bonita en ASCII =) - std::copy(n.begin(), n.end(), std::ostream_iterator< N >(os, " ")); + for (typename number< N, E >::const_iterator i = n.chunk.begin(); + i != n.chunk.end(); ++i) + os << std::hex << *i << " "; return os; } diff --git a/tests/number.cpp b/tests/number.cpp index eeafe20..75b97f0 100644 --- a/tests/number.cpp +++ b/tests/number.cpp @@ -3,22 +3,24 @@ int main() { -#if 0 - //unsigned buf[5] = { 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0 }; +#if 1 + unsigned buf[5] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0 }; //unsigned buf[3] = { 0xffffffff, 0x1, 0 }; - number< unsigned > nu = 0xffffffff; + number<> nu(buf, 4); //number< unsigned > nu2(nu); - number< unsigned > nu2 = 1u; + number<> nu2 = 1u; std::cout << "nu = " << nu << "\n\n"; std::cout << "nu2 = " << nu2 << "\n\n"; std::cout << "nu + nu2 = " << nu + nu2 << "\n\n"; #endif +#if 0 number< unsigned > nu = 0xffffffff; std::cout << "nu = " << nu << "\n\n"; nu << 5; std::cout << "nu = " << nu << "\n\n"; +#endif return 0; -- 2.43.0