Thank you very much for response.
I want to tell u the problem in detail.
I have a bitmap field that is constructed by 8 byte.
each byte will hold bitmap for 8 field. Such as i want ot insert 10101010 in the byte. For this reason i want to insert FF in a byte but it seems to be impossible. Please tell me how can i do that. I want to insert 11111111 in a byte and also want to get the content of the byte in the hex form.
Please help me.
The byte is an 8-bit, SIGNED, integer. Hence, the first bit is used to denote the sign. Hence, out of the 8 bits, you can only use the 7 bits to represent the value. Hence, 11111111 cannot be held in a byte. Hence, use short instead of byte. This should work, since short is a 16 bit, SIGNED integer and can hold from -32,768 to 32,767. Hope this helps.
Thanks all of u very much
-->>
I have completed my task;
here is the sample code;
byte[] fieldByte=new byte[8];
int[] iField = {0xFF,0xF2}; //Java compiler allows this
for (int i = 0; i < iField.length; i++)
fieldByte=(byte) iField;
receive(fieldByte);
/************************************************/
public static void receive(byte[] holder)
{
System.out.println("\n");
int[] field=new int[holder.length];
for(int i=0;i<holder.length;i++)
{field=unsignedByteToInt(holder);
printIntAsBits(field);
}
}
/*********************************************************/
public static int unsignedByteToInt(byte b) {
return (int) b & 0xFF;
}
/***********************************************************/
public static void printIntAsBits(int value)
{
int mask = 1 ><< 7;
for(int i = 0; i <8; i++)
{
System.out.print((value & mask) == 0 ? "0" : "1");
value <<= 1;
}
System.out.print(" ");
}
/****************************************/
Thanks all of u very much