Well, I believe it’s due time for me to blog something. Moods are generally bad these two days. Yesterday, nothing much interesting happened. Today, day started with a very slow internet connection. Obviously it ended up with several curses for not being able to read my regular reading material conveniently.

Okay, so, what’s my starting point? Well. I’ve had my Hello World sometime ago, I don’t remember the exact time. This time, I consider my recent activity as a more serious Java’s jump-into-the-wagon. I knew early optimization kills, but I can’t stand this huge urge and the dirty lust of having a non-looping syntax to solve byte-to-hexstring (vice versa).

I’ve read that we can use BigInteger to do the hardwork of converting bytes to hexstring via (new BigInteger(bytes)).toString(16);. That’s just fine until  found that, BigInteger will convert your bytes to a clean rpresentation of number. Thus if you have a 0×0 byte preceeding your bytes, you WON’T get that bytes in your toString(16);

Fear not my brother, we can cheat a little using some String-fu. This is also my non-smart Java move a.k.a How to repeat byte without utilizing loop.  The full String-fu for above issue would be:

String fmt = “%0″ + (bytes.length*2) + “x”);
return String.format(fmt, new BigInteger(bytes));

That’s it? The journey hasn’t finished yet my brother. As we use String-fu formatter technique, there’s a chance that our bytes got converted to negative number. Thus yields in something like -xxx.

And that’s it. I want to talk more but, onconsciously, this journey has lead me into some wisdom. I think I have a flaw in my String-fu. The repetition technique should be reworked err refactored to use repetition technique and toString(16);

I guess I should be back into my deep silent moment, align myself with the rest of the universe, searching another glimpse of wisdom. To found the real, one and the only truth on String-fu repetition.

Hmmmmmm … *humming*

Powered by ScribeFire.

Sphere: Related Content