-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntryInFile.cpp
67 lines (55 loc) · 1.26 KB
/
EntryInFile.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
//
// Created by vsx on 2024/3/3.
//
#include "EntryInFile.h"
EntryInFile::EntryInFile() {
byte=0;
}
char *EntryInFile::getCode() const {
char *code=new char[(this->code.length()-1)/8+1];
std::string temp=this->code;
while(temp.length()%8!=0){
temp.push_back('0');
}
char byte=0;
for(int i=0;i<temp.length();i++){
if(temp[i]=='1'){
byte=byte | 1;
}
if(i%8==7){
code[i/8]=byte;
byte=0;
}else{
byte=byte<<1;
}
}
return code;
}
int EntryInFile::getBits() const {
return code.length();
}
std::string EntryInFile::visual() const {
std::string temp=code;
while(temp.length()%8!=0){
temp.push_back('0');
}
return code;
}
int EntryInFile::getCodeLength() const {
return (this->code.length()-1)/8+1;
}
void EntryInFile::setCode(char *code, char bits) {
this->code.clear();
int realbits=bits-CHAR_MIN+1;
char byte;
for(char i=0;i<realbits;i++){
if(i%8==0)
byte=code[i/8];
if((byte & 0b10000000) == 0b10000000){
this->code.push_back('1');
}else if((byte & 0b10000000) == 0b00000000){
this->code.push_back('0');
}
byte=byte<<1;
}
}