/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
///1////////////////////////////////////////////////////////////////////////////
void decompression( uint32_t just_some_compressed_data, bool just_some_data[] )
{
// cout<<"\n"<<sizeof(uint32_t)<<"?"<<endl;
for(size_t i=0; i<32;i++){
just_some_data[i] = just_some_compressed_data >> (31 - i) & 1;
}
return;
}
///2/////////////////////////////////////////////////////////////////////
int decToBinary(int n)
{
// Size of an integer is assumed to be 32 bits
for (int i = 31; i >= 0; i--) {
int k = n >> i;
if (k & 1)
cout << "1";
else
cout << "0";
}
return 0;
}
///3/////////////////////////////////////////////////////
#include <bitset>
int main()
{
cout<<"\n//1//////////////////////////////////////////////////\n";
int n = 2;
decToBinary(n);
cout<<endl;
cout<<"\n//2.1//////////////////////////////////////////////////\n";
{
uint32_t compressed_data = 2;
//4294967295 (0xffffffff)
bool rezerwacjaPamieci[32];
decompression( compressed_data, rezerwacjaPamieci );
for(const auto & b:rezerwacjaPamieci) cout<<b;
cout<<'\n'<<bitset<32>(compressed_data)<<"=<bitset"<<endl;
}
cout<<"\n//2.2//////////////////////////////////////////////////\n";
{uint32_t compressed_data = 0xffffffff;
//4294967295 (0xffffffff)
bool rezerwacjaPamieci[32];
decompression( compressed_data, rezerwacjaPamieci );
for(const auto & b:rezerwacjaPamieci) cout<<b;
cout<<endl;
cout<<bitset<32>(compressed_data)<<"=<bitset"<<endl;
for(const auto & b:rezerwacjaPamieci) cout<<boolalpha<<b;
}
cout<<"\n//3//////////////////////////////////////////////////\n";
{uint32_t compressed_data = -2;
string binstr =bitset<32>(compressed_data).to_string();
for(const auto & ch:binstr) if(ch=='1') cout << "true ";
else cout<<"false ";
cout<<endl;
}
}