Is there a difference to send (int)0xFFFFFFFF or (int)0x00FFFFFF using streamConnection

i am sending arrays of ARGB pixel through a streamConnection.

To reduce the data i need to send, i decide to delete the alpha channel:

RGB_img[i] = ARGB_img[i] & 0x00FFFFFF;

when i sent the array again, looks like the the time for send the data
is not reduced.

So i wonder if both

op.writeInt(0x00FFFFFF);
and
op.writeInt(0xFFFFFFFF);

send the same amount of data.

thanx
LVL 1
KnightleyAsked:
Who is Participating?
 
aozarovConnect With a Mentor Commented:
the smallest unit is byte, but you can combine two values in one byte and then extract in a similar way in the other side.
e.g.
byte value1
byte value2
byte combined = (value1 >>> 4) & 0xf | (value2 & 0xf); // >>> is shift right as is (without mainting the sign).

and then on the other side
value1 = combined & 0xf;
value2 = (combined >> >4) & 0xf;
0
 
aozarovCommented:
You are writing int (which is always 4 bytes).
your operation just change the value of that int.
0
 
aozarovCommented:
instead you can extract from the int the 3 first bytes and then send an array of bytes instead of array of int.
in the other side combine each 3 bytes into one int.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Jim CakalicConnect With a Mentor Senior Developer/ArchitectCommented:
On the sending side, that would look something like:

    DataOutputStream out = ...
    int[] argb = ...
    out.writeInt(argb.length);
    for (int i = 0; i < argb.length; ++i) {
        out.writeByte((byte)argb[i] >> 16);
        out.writeByte((byte)argb[i] >> 8);
        out.writeByte((byte)argb[i]);
    }

And on the receiving side:

    DataInputStream in;
    int[] argb = new int[in.readInt()];
    for (int i = 0; i < argb.length; ++i) {
        argb[i] = in.readByte() << 16 | in.readByte() << 8 | in.readByte();
    }

That's all from memory so mea culpa if it doesn't compile :-) That seems like a long way around for saving one byte. I guess you plan to do that a lot of times, eh?

Jim
   
0
 
aozarovCommented:
That:
argb[i] = in.readByte() << 16 | in.readByte() << 8 | in.readByte();
should be changed to
argb[i] = ((in.readByte()  &0xff) << 16) | ((in.readByte() &0xff) << 8) | (in.readByte() & 0xff);
To avoid left bit expansion when casting byte to int.
0
 
KnightleyAuthor Commented:
is there a way only to send 1/2 byte?

like "0xF" ???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.