Raised This Month: $32 Target: $400
 8% 

[INC] Number Conversions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-21-2010 , 00:50   [INC] Number Conversions
Reply With Quote #1

This include file provides several new (?) functions to AMXX coding functionality in the number scene.
A few miscellaneous functions are included to make the rest of the functions work better, but can still be useful in other situations.

Here is the list of functions (most are self-explanatory):
Code:
// Number Conversions // by Exolent stock HexToDecimal( const szHex[ ] ) stock DecimalToHex( const iDecimal, szHexResult[ ], const iHexLen ) stock BinaryToDecimal( const szBinary[ ] ) stock DecimalToBinary( const iDecimal, szBinary[ ], const iBinaryLen ) stock BinaryToHex( const szBinary[ ], szHexResult[ ], const iHexLen ) stock HexToBinary( const szHex[ ], szBinaryResult[ ], const iBinaryLen ) // Retrives digits from a given value and returns the number of digits // // @param    iValue - The value from which to get the digits // @param    iDigits[ ] - The array to store the digits in (optional) // @param    iDigitSize - The size of the array (optional) // @param    iBase - The base of the number to find digits by (default is 10 for base 10 (decimal)) (optional) // @param    bKeepDigitOrder - Decides to start from the right side of the decimal or left (default is false) (optional) (see post for more details) // // @return    The total number of digits found // stock GetDigits( const iValue, iDigits[ ] = "", const iDigitSize = 0, const iBase = 10, bool:bKeepDigitOrder = false ) stock ReverseArray( iArray[ ], const iSize )

The bKeepDigitOrder in GetDigits() works like this:
Code:
// when false:
new iDigits[ 3 ];
GetDigits( 123, iDigits, 3, _, false );
// iDigits = { 3, 2, 1 }

// when true:
GetDigits( 123, iDigits, 3, _, true );
// iDigits = { 1, 2, 3 }
It's purpose is to decide which side of the intitial value to start from.

Feedback and suggestions are welcome
Attached Files
File Type: inc number_convert.inc (6.6 KB, 436 views)
File Type: sma Get Plugin or Get Source (number_convert_test.sma - 1064 views - 2.4 KB)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 09-22-2010 at 12:25.
Exolent[jNr] is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 09-21-2010 , 05:36   Re: [INC] Number Conversions
Reply With Quote #2

Thnx this is really helpful
BTW what does hex means ??
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
lazarev
Veteran Member
Join Date: Sep 2008
Old 09-21-2010 , 05:54   Re: [INC] Number Conversions
Reply With Quote #3

http://en.wikipedia.org/wiki/Intel_HEX
lazarev is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 09-21-2010 , 06:35   Re: [INC] Number Conversions
Reply With Quote #4

Quote:
Originally Posted by abdul-rehman View Post
Thnx this is really helpful
BTW what does hex means ??
I laughed so hard it's not even funny. Did you really just say something that you don't understand is helpful?
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-21-2010 , 07:12   Re: [INC] Number Conversions
Reply With Quote #5

For your information, that's not about -only- hex conversion.
__________________
Arkshine is offline
platzpatrone
Veteran Member
Join Date: Apr 2007
Location: Germany
Old 09-21-2010 , 07:27   Re: [INC] Number Conversions
Reply With Quote #6

ty Exolent this would be very useful in many situations
platzpatrone is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-21-2010 , 10:14   Re: [INC] Number Conversions
Reply With Quote #7

Quote:
Originally Posted by GXLZPGX View Post
I laughed so hard it's not even funny. Did you really just say something that you don't understand is helpful?
Don't make me to create a 'FAIL TOPIC' about your posts/replyes, we will laugh too...+1 Arkshine.

Gj Exolent
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 09-21-2010 , 12:29   Re: [INC] Number Conversions
Reply With Quote #8

I don't understand DecimalToBinary returning an integer...
Seta00 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-21-2010 , 12:47   Re: [INC] Number Conversions
Reply With Quote #9

Quote:
Originally Posted by Seta00 View Post
I don't understand DecimalToBinary returning an integer...
It's mainly for display purposes since it wouldn't necessarily be helpful in code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-21-2010 , 18:05   Re: [INC] Number Conversions
Reply With Quote #10

Quote:
Originally Posted by Seta00 View Post
I don't understand DecimalToBinary returning an integer...
I believe it means decimal 3 would show as decimal 11 and decimal 5 would show as decimal 101. I wondered this before also but took me a while to figure it out lol. Seems only good for arguments of printf() like functions (as Exolent said).
__________________
fysiks 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 06:14.


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