ASCII hex string to __int64

This is a discussion on ASCII hex string to __int64 within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have CString holding an ASCII hex number. ie: CString hex_number = "0x0C127D83"; I want to convert this to ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    106

    ASCII hex string to __int64

    Hello,
    I have CString holding an ASCII hex number.
    ie:
    CString hex_number = "0x0C127D83";

    I want to convert this to an __int64.

    I've seen _atoi64(), but that only does base 10 conversions. Is there something out there to do this, or do I have to write my own function?

    Thanks

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If you have MSVC.NET this'll work -

    Code:
    #include <iostream>
    #include <sstream>
    using namespace std;
    
    int main (void)
    {
    	char* a=  "0x0C127D83"; 
    	__int64 i;
    
    	stringstream ss(a);
    	ss>> hex >> i;
    	
    	cout << i;
    
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    Thanks Sorensen,
    I don't have MSVC.Net.
    I tried that with VC++6, no luck. I guess I'll keep looking, or write it myself, (I have a sneaking suspicion I'd be reinventing the wheel thouh)

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    I have my solution, if anyone is interested. I can't beleive I missed it in the help files...

    CString hex_str = "0x776FFE53B2";

    __int64 bigint;

    sscanf(( LPCTSTR )hex_str, "%I64X", &bigint );

    Good ol C runtime libs!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Signed hex string to a int
    By naruto267 in forum C Programming
    Replies: 5
    Last Post: 05-19-2008, 12:43 AM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  4. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 06:35 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21