This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generate next hexadecimal? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generate next hexadecimal?" Watch "Generate next hexadecimal?" New topic

Generate next hexadecimal?

Sylvia Allen

Joined: Apr 02, 2001
Posts: 18
I imagine this is a really dumb question, but is there some standard simple code for generating the next largest number in hexadecimal format? I need to generate sequential alphanumeric passwords. There must be some standard simple way to do this.
- SA

Sylvia Allen<br />
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Are you asking how to format an integer as a hex value? If so, just use the Integer wrapper class and call the static method toHexString(). That will take an int, and return a String formatted in hex notation.

SCJP 1.4
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Sylvia Allen:
I need to generate sequential alphanumeric passwords. There must be some standard simple way to do this.
- SA

I found the easiest way was to just create an array of all the acceptable characters in the password:
char[] passChars = {'A', 'a', ..... '9'};
Then just generate random numbers that range from 0 to 1 less than the length of the array and use that as an index into the array. Need a password of 8 characters? Generate 8 random numbers and pull 8 random characters from your array.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Generate next hexadecimal?
Similar Threads
Identify whether the string is a actual string or hexadecimal.
Another Ques from abhilash's site
hexadecimal numbers
Difficulty of shift operator and hex conversion
Hexadecimal to String and vis versa