How do you increment a hex value in java and keep the padding at the same time?
If you look at this:
Is there any sample Java code that does AES encryption exactly like this website?
You’ll see a variable called “keyHex” in the correct answer which represents hex but in string format and padded by a bunch of zeros.
Then I want to increment “keyHex” by 1 and change it from:
"00000000000000000000000000000000"
to
"00000000000000000000000000000001"
I want to keep looping and adding 1 until I reach:
"00000000000000000000000000FFFFFF"
For obvious reasons I cannot do “keyHex++”, so I would appreciate it if someone can point me in the right direction.
Well what you should keep track of is the integer value of keyHex and then simply output it like this:
You could parse keyHex to an integer first if you need to as well..
This link may be more help for that: Java – parse and unsigned hex string into a signed long