4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include <iostream> |
8 |
< |
#include <string> |
9 |
< |
#include <vector> |
7 |
> |
#include "Hexadecimal.hpp" |
8 |
|
|
9 |
< |
#include <foreach.hpp> |
9 |
> |
#include <menes-app/simple.hpp> |
10 |
|
|
11 |
< |
class Binary |
11 |
> |
int Main(const app::Options& options) |
12 |
|
{ |
13 |
< |
private: |
16 |
< |
std::vector<char> bytes; |
17 |
< |
public: |
18 |
< |
Binary(const std::string& string); |
19 |
< |
template <typename Type> |
20 |
< |
Binary(const Type& type); |
21 |
< |
operator std::string() const; |
22 |
< |
}; |
13 |
> |
Represent represent; |
14 |
|
|
15 |
< |
Binary::Binary(const std::string& string) |
25 |
< |
{ |
26 |
< |
throw; |
15 |
> |
return 0; |
16 |
|
} |
17 |
|
|
18 |
< |
template <typename Type> |
30 |
< |
Binary::Binary(const Type& type) : bytes(sizeof (type)) |
18 |
> |
Represent::Represent() |
19 |
|
{ |
20 |
< |
char* type_(reinterpret_cast<char*>(const_cast<Type*>(&type))); |
20 |
> |
std::string hello("Hello, World!"); |
21 |
|
|
22 |
< |
_mforeach (std::vector<char>, byte, bytes) *byte = *type_++; |
35 |
< |
} |
22 |
> |
api::Cerr << Binary(hello) << " = " << Hexadecimal(hello) << " = " << ext::String(hello) << ios::NewLine; |
23 |
|
|
24 |
< |
Binary::operator std::string() const |
38 |
< |
{ |
39 |
< |
std::string string; |
24 |
> |
_sforeach (std::string, atom, hello) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(atom, 1) << ios::NewLine; |
25 |
|
|
26 |
< |
_rforeach (std::vector<char>, byte, bytes) |
42 |
< |
{ |
43 |
< |
_rfor (char, bit, 0, 8) |
44 |
< |
{ |
45 |
< |
string += 1 & *byte >> bit ? '1' : '0'; |
46 |
< |
} |
47 |
< |
} |
26 |
> |
ext::String hello_(hello); |
27 |
|
|
28 |
< |
return string; |
50 |
< |
} |
28 |
> |
api::Cerr << Binary(hello_) << " = " << Hexadecimal(hello_) << " = " << hello_ << ios::NewLine; |
29 |
|
|
30 |
< |
std::ostream& operator<<(std::ostream& out, const Binary& binary) |
53 |
< |
{ |
54 |
< |
return out << std::string(binary); |
55 |
< |
} |
30 |
> |
_foreach (ext::String, atom, hello_) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(*atom) << ios::NewLine; |
31 |
|
|
32 |
< |
int main(int argc, char* argv[]) |
58 |
< |
{ |
59 |
< |
std::string hello("Hello, World!"); |
32 |
> |
_fori (index, -10, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
33 |
|
|
34 |
< |
_foreach (std::string, atom, hello) |
62 |
< |
{ |
63 |
< |
std::cout << Binary(*atom) << " = " << *atom << std::endl; |
64 |
< |
} |
65 |
< |
|
66 |
< |
_fori (index, -10, 11) |
67 |
< |
{ |
68 |
< |
std::cout << Binary(index) << " = " << index << std::endl; |
69 |
< |
} |
70 |
< |
|
71 |
< |
_foru (index, 4294967286, 11) |
72 |
< |
{ |
73 |
< |
std::cout << Binary(index) << " = " << index << std::endl; |
74 |
< |
} |
75 |
< |
|
76 |
< |
for (float index(-1.0); index < 1.0; index += 0.1) |
77 |
< |
{ |
78 |
< |
std::cout << Binary(index) << " = " << index << std::endl; |
79 |
< |
} |
80 |
< |
|
81 |
< |
for (double index(-1.0); index < 1.0; index += 0.1) |
82 |
< |
{ |
83 |
< |
std::cout << Binary(index) << " = " << index << std::endl; |
84 |
< |
} |
34 |
> |
_foru (index, 0xFFFFFFF6, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
35 |
|
|
36 |
< |
return 0; |
36 |
> |
for (float index(-1); index < 1.1; index += float(0.1)) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
37 |
> |
|
38 |
> |
for (double index(-1); index < 1.1; index += 0.1) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine; |
39 |
|
} |