Raised This Month: $ Target: $400
 0% 

Convert to hex


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 09-07-2007 , 11:43   Convert to hex
Reply With Quote #1

I couldn't find any natives for converting a decimal number to hex.

I have an RGB value that would be a lot happier as a hex value ( for showing in an MOTD window) and I was wondering if there's an easy way.

I could do write an rgb_to_hex() function, but if there's an obvious way I don't know about then I'd feel like a tool.

EDIT: Well since I didn't find one, anyone who reads this hoping for an answer can use this:
Code:
stock rgb_to_hex(r,g,b,output[8]) {     new letter1,letter2 ;     letter1=r/16     letter2=r%16     output[0]=36 // $ sign     output[1]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[2]=( letter2 < 10 ) ? letter2+48 : letter2+55     letter1=g/16     letter2=g%16     output[3]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[4]=( letter2 < 10 ) ? letter2+48 : letter2+55     letter1=b/16     letter2=b%16     output[5]=( letter1 < 10 ) ? letter1+48 : letter1+55     output[6]=( letter2 < 10 ) ? letter2+48 : letter2+55     output[7]=0 }
I think it works ... it seems fine for my testing.

It seems weird to have the string one character too long, but AMX gets a tad confused if you don't terminate your strings in my experience.

Last edited by purple_pixie; 09-07-2007 at 12:15.
purple_pixie is offline
Reply



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 16:17.


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