-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatarate.cpp
More file actions
35 lines (31 loc) · 743 Bytes
/
datarate.cpp
File metadata and controls
35 lines (31 loc) · 743 Bytes
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
#include "datarate.h"
DataRate::DataRate() {}
DataRate::~DataRate() {}
float const DataRate::MegaBits(const int words, const long nanoSec) {
int bits = words * 32;
float microSec = 0;
microSec = nanoSec / 1000;
return bits / microSec;
}
string const DataRate::GigaOrTera(float const megabits) {
float speed = 0;
string unit = "";
if(megabits >= 1000) {
speed = megabits / 1000;
speed = floor(speed * 100.0) / 100.0;
unit = " Gigabits/s";
}
else if (megabits >= 1000000) {
speed = megabits / 1000000;
speed = floor(speed * 100.0) / 100.0;
unit = " Terabits/s";
}
else {
speed = megabits;
speed = floor(speed * 100.0) / 100.0;
unit = " Megabits/s";
}
ostringstream ss;
ss << speed;
return ss.str() + unit;
}