1

I have this code in C#

byte[] t = {6, 250, 215}.

But in Java is

byte[] t = {6, -6, -41}.

How to solve this problem?

3
  • 1
    c# byte and java byte are not equivalent. Java's bytes are signed. Commented Jul 21, 2016 at 18:29
  • So if I use md5 encryption in C # I will never be able to convert in java? Commented Jul 21, 2016 at 18:38
  • 1
    Both arrays are { 0b00000110, 0b11111010, 0b1101011 }. They have different interpretations. Commented Jul 21, 2016 at 19:02

1 Answer 1

5

How to solve this problem

the 1st is read about how java represents data types..:

byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.

as @bradimus statements, java's byte is an 8-bits 2 complement signed int but in C# you will never see a negative byte value

Hint:

if you consider to make a conversion...

-6 in java can be 256+(-6) = 250 in C#

and carefully consider the max and min in a java-byte if you need to convert from C# to java....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.