Question

How do I conver the followint 32 bit HEX to 6 digit decimal?

MD5: 9d10f0693b9d8e6c32c33d1e9be377b5

I hashed certain field to get the above. However, I would need to generate 6 digit PIN.

Was it helpful?

Solution

(your md5 is not 32 bits long but 128 (32 hex characters * 4bits/char) but it's not plain relevant... sorry)

The pin will not hold the 128 bits information the hash contains, so you have to take a subpart of it.

I'll assume your hash is a standard java String.

if you need the pin as a 6 digits int :

int pin = hash.hashCode() % 1e6;

I let you check if this method comply with your "security" exigences :) hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top