On Thu, Dec 31, 2009 at 01:01:56PM -0500, Garcia, Maurice wrote:
> Can anyone help me to do this in TCL Blend:
>
>
>
> public static final byte[] intToByteArray(int value) {
>
> return new byte[] {
>
> (byte)(value >>> 24),
>
> (byte)(value >>> 16),
>
> (byte)(value >>> 8),
>
> (byte)value};
>
> }
>
>
>
>
>
> This does not work???
>
> set integer [java::new Integer {254}]
>
> set bVpnId [java::new {byte[]} 1 [java::cast byte $integer]]
>
Note that Java byte datatype is signed, so legal values are -128 to +127.
To coerce 0-255 into a byte, try:
set val 254
set bVpnId [java::new {byte[]} 1 [expr $val > 128 ? [expr $val - 256] : $val]]
puts [$bVpnId get 0]
I'm more of a Jacl user rather than TclBlend, but since they both share
the 'java' package, I believe this also holds true for TclBlend.
--
Tom Poindexter
tpo...@ny...
|