Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

By using UUID is it possible to generate a 16 character String?

Tags:

java

uuid

I have tried UUID and its generating 32 character string.But I want 16 character unique string

like image 967
Rishi Rdy Avatar asked Oct 28 '25 05:10

Rishi Rdy


2 Answers

Since a UUID is 128 bits, 128 / 16 = 8, you need to cram 8 bits into each character. So you could express the UUID as a char[16] -- but it would not be printable as a string.

ASCII only uses 7 bits, and many of those are non-printable.

You could possibly express an 8 bit number as a String of length 1 by identifying 256 printable unicode codepoints (for example, dingbats, chinese characters etc.) and mapping these to values. This would allow you to display a UUID in an 8-character-wide space on unicode-capable displays. You would probably be able to copy-and-paste these, but care would be needed moving them around - manually typing them would be challenging.

like image 120
slim Avatar answered Oct 30 '25 23:10

slim


It needs to have 32 characters to be unique.

Lazy way: only tke the first 16 chars (might not always work)

Proper way: find a formula which can break down a 32 character UUID to a 16 character UUID.

Different way: Use the hashcode instead (only works when needing UUID's once)

like image 44
kleopi Avatar answered Oct 30 '25 22:10

kleopi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!