mercredi 1 avril 2015

Universal Char rendering

I was watching a Lynda's Tutorial and there was some C mixed with C++.


http://ift.tt/19HeOMP


In this picture the guy had a string with Hex in it and the compiler rendered it as Universal Char any how i decided to run a code that can print all of these universal characters. I did a dec to hex program then i attached this a string starts with U.


the question is ::: how can i make the program reads it like the guy in lynda did ??





#include <iostream>
#include <cmath>
using namespace std;

const int HexBase=16;
const int HexMax=15;
const int UniCharMaxPrint=100;
const int ASCCIAlphaCapBase=48;


int main() {

int DecNum = 0;
int sizeHex= 5;

for (int j=0; j < UniCharMaxPrint; j++)//prints 100 unviersal Chars
{
int DecNumCopy = DecNum;
int resultDiv =0;
string HexChar=" ";
string HexNum ="X";
string UniNum ="U";

for (int i = sizeHex; i >=0; i--)
{
//Dec calcultion
resultDiv = (DecNumCopy/(int)(pow(HexBase,i)));
DecNumCopy = DecNumCopy - ((int)(pow(HexBase,i)) * resultDiv);
if ((i==0) && (resultDiv>HexMax)){cout <<"Error # is Too large"<<endl;}

//Get the equivalente Hex charcter
if ((resultDiv >= 0)&&(resultDiv <= 9))
{ HexChar = ASCCIAlphaCapBase + resultDiv;}
else if ((resultDiv >= 10)&&(resultDiv <= 15))
{ switch (resultDiv)
{ case 10 : {HexChar='A'; break;};
case 11 : {HexChar='B'; break;};
case 12 : {HexChar='C'; break;};
case 13 : {HexChar='D'; break;};
case 14 : {HexChar='E'; break;};
case 15 : {HexChar='F'; break;};
}
}
else {HexChar='*';};

//Add to the result string
HexNum.append(HexChar);
UniNum.append(HexChar);


}//endfor
DecNum++;
cout<< UniNum << endl;
}
return 0;
}



Aucun commentaire:

Enregistrer un commentaire