-
Notifications
You must be signed in to change notification settings - Fork 0
/
Byte.cpp
73 lines (57 loc) · 945 Bytes
/
Byte.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Byte.cpp
* new_LT
*
* Created by 刁培倫 on 2011/5/5.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include<vector>
#include<string>
#include"CodeSim.h"
using namespace std;
namespace CodeSim {
Byte::Byte(){
value = 0;
setErased(false);
}
//template<class T>
Byte::Byte(int t){
if (t == -1) {
setErased(true);
}
else{
value = t & mask;
setErased(false);
}
}
// template<class T>
// Byte Byte::operator=(T t){
// value = t;
// return *this;
// }
Byte Byte::operator+(Byte t){
return Byte((value ^ t.value) );
}
// Byte Byte::operator*(Byte t){
// return Byte(this->value & t.value);
// }
string Byte::toString()
{
if (isErased()) {
return "********";
}
unsigned int tmp = value;
string s = "";
for (int i=0; i<8; i++) {
if (tmp & 1) {
s = '1'+s;
}
else {
s = '0'+s;
}
tmp = tmp>>1;
}
return s;
}
}