Raised This Month: $12 Target: $400
 3% 

Converting Hexadecimal to Decimal


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DotNetJunkie
Senior Member
Join Date: May 2005
Location: In front of my pc
Old 10-21-2006 , 13:40   Converting Hexadecimal to Decimal
Reply With Quote #1

If you are unfamiliar with hexadecimal numbers please look here:
http://www.permadi.com/tutorial/numHexToDec/

I looked around and didn't find a hexadecimal to decimal conversion function
and I needed one for one of my projects so I wrote one.

Code:
public HexToDec(value[])
{
	new string[32];
	copy(string,sizeof(string)-1,value);
	strtoupper(string);
	new temp = 0;
	new len = strlen(string);
	new i = len;
	while( i > 0 )
	{
		new dec = 0;
		switch( string[i-1] )
		{
			case 'A': dec = 10;
			case 'B': dec = 11;
			case 'C': dec = 12;
			case 'D': dec = 13;
			case 'E': dec = 14;
			case 'F': dec = 15;
			case '0': dec = 0;
			case '1': dec = 1;
			case '2': dec = 2;
			case '3': dec = 3;
			case '4': dec = 4;
			case '5': dec = 5;
			case '6': dec = 6;
			case '7': dec = 7;
			case '8': dec = 8;
			case '9': dec = 9;
		}
		temp += dec*power(16,(len-i));
		i--;
	}
	return temp;	
}
__________________
DotNetJunkie is offline
Send a message via ICQ to DotNetJunkie Send a message via AIM to DotNetJunkie Send a message via MSN to DotNetJunkie Send a message via Yahoo to DotNetJunkie
<<<Anonysmous>>>
BANNED
Join Date: Apr 2008
Old 01-06-2009 , 17:18   Re: Converting Hexadecimal to Decimal
Reply With Quote #2

My dayz This is awesome, dude this helped me alot .... really, not just to make u proud, I used this for some stuff like map originz an all !
+k!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<<<Anonysmous>>> is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 01-06-2009 , 22:20   Re: Converting Hexadecimal to Decimal
Reply With Quote #3

Code:
public HexToDec(hex[])
{
    new i, result, value
    while((value = isxdigit(hex[i++])) != -1)
    {
        result = result * 16 + value
    }
    return result
}
 
isxdigit(ch)
{
    if(!ch)
        return -1
    
    if('0' <= ch <= '9')
        return ch - '0'
    
    ch &= ~0x20
    if('A' <= ch <= 'F')
        return ch - 'A' + 10
    
    return -1
}
try this
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 01-11-2009 , 16:22   Re: Converting Hexadecimal to Decimal
Reply With Quote #4

Very nice Jim! thank you, i'll use that in C++
DotNetJunkie, same as @ jim.
__________________

anakin_cstrike is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 01-19-2009 , 17:46   Re: Converting Hexadecimal to Decimal
Reply With Quote #5

Quote:
Originally Posted by anakin_cstrike View Post
i'll use that in C++
http://www.google.com/search?q=strto...ient=firefox-a
__________________
fyren sucks
sawce is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode