Jump to content
Sign in to follow this  

Java: Decimal To Hex

Recommended Posts

well Im doin a project for my java class and our teacher is tarded...

he's makin us make a java gui program that converts back and forth from hexidecimal and decimal... got the hex2dec part down cause he gave us a file for it a while back....

I know how 2 convert decimal to hex, but programming it seems a little hard cause I dont know how to make code that will place letters and numbers into a new string once Ive done the conversion of the decimal...

I was wonderin if anyone knew where I could find a sample dec2hex java file or an answer to my problem....

once I know a way to do this, I think I know a way to input the char's and numbers from right to left into the string....


Share this post

Link to post
Share on other sites

I already have a method for converting hex to dec...

I need to convert dec to hex, and I pretty much know exactly what to do,

I just dont know how to input individual characters into a string at different times.... I looked at the second link but didnt see anything right away...

Ill study it later on... maybe Ill find somethin in there I could use...



one more thing....

lookin for actual java code, not javascript...

if anyone knows any good sites for actual java please post... thanx

Share this post

Link to post
Share on other sites

working by memory the rough answer is this


to convert decimal to hex. its quite simple. Say the rgb for the color is 178 ,164,45.


the first letter is based on dividing 178 by 16 =11

the second letter is based on the portion left from the first figure. 178-(16*11)=2.


the third letter comes from dividing 164 by 16=10

the fourth letter is the remainder left from the sum above eg 164-(16*10)=4


the fifth letter comes from dividing 45 by 16=2

the sixth letter cmes from the remainder to the above=13


now you have the figures. 11-2-10-4-2-13


now you have to convert these to hexi strings.


this is simple. 0=0;1=1;2=2;3=3;4=4;5=5;6=67=7;8=8;9=9;a=10;



so the string 11-2-10-4-2-13 becomes #b2a42d


try my website it needs visitors



Share this post

Link to post
Share on other sites

thanx for the input... this post is really old...

back then he was giving us simple excercises to get used to programming..

today I just finished a game we were doing for a couple weeks...

given more time I could do a much much better game...

my friends made a mortal kombat game which was pretty cool..

once I get the code back from my teacher I'll post it on a page and

show ya guys... I still have to add some stuff to it though since we

only had like less than an hour a day for 2 weeks...

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...