// The purpose of this code is to convert decimal floating point Numbers to hexadecimal
//把浮点数normalize到2000到3FFF的区间上
#include <iostream>
#include <assert.h>
#include <cassert>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
#include<algorithm>
using namespace std;
constexpr auto FILE_SOURCE1 = "D:\\n3_in.txt";
constexpr auto FILE_SOURCE2 = "D:\\n3_out.txt";
int main()
{
fstream my_input;
fstream my_output;
char c1;
int count = 0;
my_input.open(FILE_SOURCE1, ios::in);
my_output.open(FILE_SOURCE2, ios::out);
if (my_input.fail())
{
return 0;
}
vector<float> floats;
string line;
//Read float
float max_number = 0;
//get the greatest value
while (getline(my_input, line))
{
istringstream iss(line);
float val;
iss >> val;
if (val > max_number)
{
max_number = val;
}
floats.push_back(val);
}
my_input.close();
vector<int> ints;
for (int i = 0; i < floats.size(); i++)
{
int bbb;
bbb = (floats[i] / max_number) * 8191 + 8192;
//bbb = floats[i];
ints.push_back(bbb);
}
for (int i = 0; i < ints.size(); i++)
{
my_output << hex << ints[i] ;
}
my_output.close();
return 0;
}