-1

I need to convert a Delphi function to Java function. This function convert a byte decimal to byte bcd:

function ByteToBCD(Number : byte) : byte;
begin
    result:= ((Number div 10) shl 4) or (Number mod 10);
end;
Rafael Guerra
  • 45
  • 1
  • 7
  • `div` is `/`, `shl` is `<<` and `or` is `|`. A bigger problem is that there is no unsigned byte type in Java. What type do you want to use? Do you know any Java? Or is it Delphi that you don't understand? What are you stuck on? – David Heffernan Jul 27 '15 at 13:04
  • Also, could you please ask a direct question. Here you've just told us that you have some job to do and left us to work out what your question is. I hope you aren't just hoping we'll do it all for you. We prefer to help people that are keen to learn. – David Heffernan Jul 27 '15 at 13:06
  • I don´t want anyone solve anything for me. I just need an little explanation of conversion with bcd and a relationship between the operators used in Delphi and Java, just as you did in parts. – Rafael Guerra Jul 27 '15 at 13:11
  • Please state that in the question. Oh, I see I missed `mod` being `%`. Of course both languages are well documented and there operators are well known. It would be better if you read the docs first, and then asked for clarification of anything that you don't understand. As presented, one might suspect you of being lazy. Show us that you are not by adding what you know to the question, and asking a specific question. – David Heffernan Jul 27 '15 at 13:13

1 Answers1

2

You can do this

public static int byteToBCD(byte b) {
    assert 0 <= b && b <= 99; // two digits only.
    return (b / 10 << 4) | b % 10;
}

It is not clear what you are stuck on but it the answer is trivia.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130