?
Solved

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

Posted on 2005-05-03
6
Medium Priority
?
600 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:Knightley
  • 4
6 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13921051
You are writing int (which is always 4 bytes).
your operation just change the value of that int.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13921061
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
 
LVL 19

Assisted Solution

by:Jim Cakalic
Jim Cakalic earned 80 total points
ID: 13921166
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Expert Comment

by:aozarov
ID: 13921205
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
 
LVL 1

Author Comment

by:Knightley
ID: 13921762
is there a way only to send 1/2 byte?

like "0xF" ???
0
 
LVL 15

Accepted Solution

by:
aozarov earned 160 total points
ID: 13922086
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question