[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

bytes, chars, and BigIntegers, oh my!

Hello everyone.

For my aforementioned encryption program, I was rather hoping to use
Sun's BigInteger implemention. It has a constructor that can accept
arrays of bytes, and a method to return an array of bytes.

I could take an egotistical American view of the world, and cast chars
into bytes -- but people in other countries might not be so fond of this

And now, my first question -- can anyone think of a better method than
casting chars to ints, and using casting and shifting turning each int
into four bytes? I imagine this would be slow, slow, slow. All the bits
are lined up so prettily already, the casting and shifting mangles
things badly. Also, if "int" ever grows in length from four bytes, my
program might cease to function. Hehe. This also wastes two bytes per
char. I could do more magic to fit two chars per int, I suppose...

My second question -- some of the methods (such as
String.getBytes(String enc)) take an encoding method -- and I haven't
found documentation on these guys anywhere. I imagine "ascii" "ebcdic"
"unicode" would be the names of encoding methods I could choose from,
but I haven't found any uses of them yet. Pointers to resources would be
much appreciated. :) They say the VM will use whatever is native on the
system if the programmer doesn't specify, so I figure I should specify.

Am I wrong on this point too?

Thanks everyone.

Seth Arnold | http://www.willamette.edu/~sarnold/
Hate spam? See http://maps.vix.com/rbl/ for help

Reply to: