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

[TUT] Hexadecimal system


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diablix
Senior Member
Join Date: Jan 2010
Location: Warsaw, Poland
Old 08-16-2011 , 21:06   [TUT] Hexadecimal system
Reply With Quote #1

Quote:
Originally Posted by Wikipedia
Hexadecimal system - In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16.
I'll just tell you an usage of this system in PAWN.

I prefer this system instead of decimal system. Why?
It's easier to convert those integers to binary system which is used by computers. It also looks kinda cooler

Some examples of integers in HEX system

  • 0xFF
  • 0x10
  • 0x25
  • 0xA
  • 0xAF
How to convert HEX integer into decimal one?
It is quite easy.

0x10

Just don't mind about this first zero. Imagine that x = 16.

0x10 = x(16) * 1 + 0 = 16

Just multiple first number after x (As I said imagine that x = 16)
The rest integers you have to sum.

We multiplied 16 by 1 and we add there a 0

Some more examples

0x21 = x(16) * 2 + 1 = 33

0xFF = x(16) * 15 + 15 = 255

Oh wait! What is this 'F' character?

In this system you can also use letters instead of numbers.

Code:
A = 10
B = 11
C = 12 
D = 13 
E = 14
F = 15
And now.. why I said don't mind about this 0 ?
Compiler detects that this integer is in HEX System by 0x at the begining.
You don't need to use this zero in conversion.

How would it look in a PAWN script?

PHP Code:
#include <amxmodx>

#define VERSION "0.1"

new const g_iHEX[] = {
        
0x14,   //20
        
0x25,   //37
        
0x15,   //21
        
0x05,   //5
        
0x50,   //80
        
0xA,    //16
        
0xFF    //255
};

public 
plugin_init() {
        
register_plugin("HEX TO DEC"VERSION"diablix")
        
register_clcmd("say /test""cmdHexToDec");
}

public 
cmdHexToDec(id){
        new 
sMessage[0x80]; // 0x80 = 16 * 8 + 0 = 128
        
new iMesSize formatex(sMessagesizeof sMessage 1"DEC READEN FROM HEX : ");
        
        for(new 
sizeof g_iHEX ++)
                
iMesSize += formatex(sMessage[iMesSize], (sizeof sMessage 1) - iMesSize"%d "g_iHEX[i]);
        
        
set_pev(idpev_effectsg_iHEX[5]); // 0xA = 16 * A(10) = 16

        
client_print(id3sMessage);
        
        return 
1;

I could make some mistakes cause of my weird english. Sorry bros
diablix is offline
Send a message via Skype™ to diablix
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-16-2011 , 21:40   Re: [TUT] Hexadecimal system
Reply With Quote #2

PHP Code:
new const g_iHEX[] = { 
     
0x14//20 
     
0x25//37 
     
0x15//21 
     
0x05//5 
     
0x50//80 
     
0xA//16 
     
0xFF //255
}; 
0xA = 10, not 16

Your tut only covers hex values <= 255, which it is typically easier to just use decimals. You should also discuss how larger values are stored which I think will better explain hexadecimal.

You should post a link to a calculator so people can calculate they own values. Also, this link helps. Here's another.
__________________

Last edited by Bugsy; 08-16-2011 at 22:09.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-16-2011 , 22:08   Re: [TUT] Hexadecimal system
Reply With Quote #3

Quote:
Originally Posted by diablix View Post
It's easier to convert those integers to binary system which is used by computers.
It's easier for who? Why would I need to convert to binary? I've rarely needed to know anything in binary. That's why I use a high-level programming language.

Quote:
Originally Posted by diablix View Post
It also looks kinda cooler
Honestly, IMO, it just makes it harder to read.
__________________

Last edited by fysiks; 08-16-2011 at 22:10.
fysiks is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-16-2011 , 22:10   Re: [TUT] Hexadecimal system
Reply With Quote #4

new sMessage[0x80]
this kind of stuff just makes ur code unreadable, code is for people to read, I don't see any cool thing to declare an array with hex as its size.
__________________
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
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-16-2011 , 22:56   Re: [TUT] Hexadecimal system
Reply With Quote #5

I agree with you both, I would never use hex to replace simple numeric values just for the sake of using hex. Why use 0x13 when 19 will do? It would be especially confusing for those viewing code who are not versed in hexadecimal.

The only time I would agree with his statement is when working with bit masks. In this instance they are actually easier to use than decimal numbers.

1111 1111 = binary
255 = decimal
FF = hex

1111 0000 1111 0000 = binary
61680 = decimal
F0F0 = hex

1111 0000 1111 1111 1111 = binary
987135 = decimal
F0FFF = hex
__________________

Last edited by Bugsy; 08-16-2011 at 23:02.
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 08-16-2011 , 23:35   Re: [TUT] Hexadecimal system
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
I agree with you both, I would never use hex to replace simple numeric values just for the sake of using hex. Why use 0x13 when 19 will do? It would be especially confusing for those viewing code who are not versed in hexadecimal.

The only time I would agree with his statement is when working with bit masks. In this instance they are actually easier to use than decimal numbers.

1111 1111 = binary
255 = decimal
FF = hex

1111 0000 1111 0000 = binary
61680 = decimal
F0F0 = hex

1111 0000 1111 1111 1111 = binary
987135 = decimal
F0FFF = hex
Could you explain 'bit masks' a little bit more and the usage in AMXX scripting?

Thanks.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-17-2011 , 00:19   Re: [TUT] Hexadecimal system
Reply With Quote #7

Quote:
Originally Posted by nikhilgupta345 View Post
Could you explain 'bit masks' a little bit more and the usage in AMXX scripting?

Thanks.
Look into binary.
Bugsy also wrote a tutorial on bits.
__________________
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 08-17-2011 , 00:19   Re: [TUT] Hexadecimal system
Reply With Quote #8

Thanks Bugsy, that's a really good point.
__________________
fysiks is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 08-17-2011 , 01:32   Re: [TUT] Hexadecimal system
Reply With Quote #9

You didnt explained about numbers higher than 0xFF like 0xF0FFF
So can you please cover this part as well ? other wise it will confuse people like me.
__________________

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
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-17-2011 , 01:46   Re: [TUT] Hexadecimal system
Reply With Quote #10

what should it cover ? It's just a numeral system, nothing to explain on higher than 0x10
__________________
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
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 04:06.


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