Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:13:45+00:00 2026-06-04T05:13:45+00:00

How can I get decimal from string hexdecimal: I have unsigned char* hexBuffer =

  • 0

How can I get decimal from string hexdecimal:
I have unsigned char* hexBuffer = "eb89f0a36e463d";.
And I have unsigned char* hex[5] ={'\\','x'};.
I copy from hexBuffer first two char "eb" to hex[2] = 'e'; hex[3] = 'b';.
Now i have string "\xeb" or "\xEB" inside hex.
As we all know 0xEB its ahexdecimal and we can convert to 235 decimal.

How can I convert "\xEB" to 235(int)?

(Thanks to jedwards)
My Answer (maybe it will be useful for someone):

/*only for lower case & digits*/ 
unsigned char hash[57] ="e1b026972ba2c787780a243e0a80ec8299e14d9d92b3ce24358b1f04";  
unsigned char chr =0;  
int dec[28] ={0}; int i = 0;int c =0;  
while( *hash )  
{  
c++;  
(*hash >= 0x30 && *hash <= 0x39) ? ( chr = *hash - 0x30) : ( chr = *hash - 0x61 + 10);  
*hash++;  
if ( c == 1) dec[i] = chr * 16; else{ dec[i] += chr; c = 0; dec[i++];}  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:13:47+00:00Added an answer on June 4, 2026 at 5:13 am

    Typically I see homebrew implementations of hex2dec functions look like:

    #include <stdio.h>
    
    unsigned char hex2dec_nibble(unsigned char n)
    {
        // Numbers
        if(n >= 0x30 && n <= 0x39)
        {
            return (n-0x30);
        }
        // Upper case
        else if(n >= 0x41 && n <= 0x46)
        {
            return (n-0x41+10);
        }
        // Lower case
        else if(n >= 0x61 && n <= 0x66)
        {
            return (n-0x61+10);
        }
        else
        {
            return -1;
        }    
    }
    
    
    int main()
    {   
        unsigned char t;
        t = '0';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'A';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'F';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'G';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'a';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'f';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = 'g';  printf("%c = %d\n", t, hex2dec_nibble(t));
        t = '=';  printf("%c = %d\n", t, hex2dec_nibble(t));
    }
    

    Which displays:

    0 = 0
    A = 10
    F = 15
    G = 255
    a = 10
    f = 15
    g = 255
    = = 255
    

    I’ll leave it as an exercise for you to go from nibble to byte and then from byte to arbitrary length string.

    Note: I only used #include and printf to demonstrate the functionality of the hex2dec_nibble function. Its not necessary to use these.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In JavaScript, when converting from a float to a string, how can I get
can i get validation on weight which can take decimal values and also integer.
I can get easily see what projects and dlls a single project references from
Logging can get complicated, quickly. Considering that you have some code, how do you
I can get the executable location from the process, how do I get the
I have a custom user type that is used to map from a decimal
Greetings. Imagine you've been given a string (from somewhere you can't control). In that
How can I get a float or real value from integer division? For example:
Is this the proper REGEX to remove trailing decimal and zeroes from a string?
I have the following data structure: public class Person { public string Name{get;set;} public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.