Problem in adjusting the range of long value
Hi all
I have problem
I have application running in C language which sends data to other application which is running in java .. Its through socket communication
My doubt is in C the size of long is 4bytes and in java 8bytes
my C application is sending a negative long value
so with C long has 32 bit in which the last bit is for signed/unsigned
but the value when i convert in java will i get postive value or negative value
In java long is 64 bits and last is for signed/unsigned
So when i convert that C long value which is a negative value to Java long value it come under the range of postive java long value
How to solve this
# 5
Well I think you need to make up your mind what the problem is. In your OP you said this:
> my C application is sending a negative long value
and now you're saying this:
> but C is sending only positive long value.
In any case all you have to do is convert the 4 bytes to a Java integer correctly, which is just a few shifts and masks.
But it would be both easier and clearer to use the methods of DataInputStream directly on the input stream to give you the appropriate datatypes as they arrive, without using the byte[] array at all.
ejpa at 2007-7-9 6:15:06 >

# 6
mate
The variable in which the C stores its value is a signed long value
k...so it send only positive value. But when the value overflows it start sending negative values.
So till C is sending postive values no problem ... and when its start sending negative value and if my java also get negative value no problem
but wat happening is while receiving i get positive value
But i don't understand where the problem is in java or c
anyhow thanks for ur comment
take care
bye prakash
# 9
Okay, strip it down:
What is the range of values being sent? What's the minimum and maximum numerical values that you want to communicate?
How many bytes are those values being sent in?
How is it being encoded?
Give some examples of values you're sending that are being interpreted incorrectly: What is the value? What is the byte pattern? What value is Java interpreting it as?