Hi,
How can i convert a hexadecimal to binary in qt?
I am trying as below but its not working....

I am reading hexadecimal as a string(actually this number resides inside a file, hence reading as a string)
then converting this string into hexadecimal,
then converting this to binary...
the code as shown below...

this function takes hexadecimal value as string then returns the binary corresponding value
Qt Code:
  1. int FilterColl::BinVal(QString str)
  2. {
  3. bool ok;
  4.  
  5. int iVal=str.toInt(&ok,16);
  6. if(ok)
  7. {
  8. QString hexnum=QString::number(iVal,16);
  9. std::cout<<"THE HEX VALUE IS:"<<hexnum.toStdString()<<endl;
  10. bool ok1;
  11. iVal=hexnum.toInt(&ok1,2);
  12. if(ok1)
  13. {
  14. cout<<"THE BINARY VALUES IS:"<<iVal<<endl;
  15. return iVal;
  16. }
  17. }
  18. else
  19. {
  20. cout<<"CONVERSION FAILED !!!!!!!!!!!!!"<<endl;
  21. iVal=0;
  22. return (iVal);
  23. }
  24. }
To copy to clipboard, switch view to plain text mode