PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] How to convert hex into dec string in C++?

 August 11, 2022     c++, decimal, hex, string, utf-8     No comments   

Issue

I'm using C++11. Is there a function that gets the string of hex and turns it into decimal?

I've tried to find something about unicode() function that I saw somewhere in StackOverflow, but I couldn't find any information about it.

For example, we have a symbol hex: U+03C0. How to turn it into dec: 960?

Let's imagine this:

char* pi_symbol = hexToDec("U+03C0");
cout << "The pi dec is " << pi_symbol << endl;

And get this:

The pi dec is 960


Solution

You can use std::hex:

#include <iostream>
#include <sstream>
int main()
{
    int n;
    std::istringstream("03C0") >> std::hex >> n;
    std::cout << n;
}


Answered By - Oblivion
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing