Question

  int diny6h = Integer.parseInt(Integer.valueOf(diny6).toString(), 10);
  int diny7h = Integer.parseInt(Integer.valueOf(diny7).toString(), 10);
  diny6h=diny6h-32;
  diny7h=diny7h-32;
  System.out.println(diny6h + " + " + diny7h);
}

Incoming: diny6=30 diny7=20

printed: diny6h=16 diny7h=00

What i want: diny6h=10 diny7h=00

What am i doing wrong here?

EDIT: well.. the numbers are send as hexadezimals and received as decimals, because the other numbers in the block (not diny6 and 7, but diny1 to diny5) are needed as hexadezimals. but diny6 and 7 are needed as decimals but im not able to get them the way i want i want to send a 35(hex) it comes in as 53(dec) and should be pirnted out as 10(dec). Same issue: want to send a 20(hex) it comes as a 32(dec) and should printed as 0

In short:

I send the 35, received as 53, but i need the 35 to reduce it by 20 and get the 15... how do i do that?

EDIT:

I am sorry for my yesterdays cofusing. WHat i need is to convert my received value to a BCD-number... nothing with hex ^^ should i delete this question now?

Was it helpful?

Solution 2

Was my own fault, misunderstood the meaning of what i wanted to do and ignored some hardware relevant requirements. Question totally wrong asekd.

OTHER TIPS

nothing is wrong.

for diny6:

30(hex) - 32(dec) = 30(hex) - 20(hex) = 10(hex) = 16(dec)

similarly for diny7.

integers by default are printed in decimal, thats why you get 16. if you want to print the number in hex format do something like:

System.out.println(String.format("%x",diny6));

update:

i'm afraid you don't fully understand mathematical bases. hex and dec are just representations, an int variable isn't decimal or hex - it is just a number.
1. read the string representation of the number.
2. do whatever computations you need (and dont concern your self with the base during this stage).
3. print the result either as decimal or hex using format strings.
4. read up about the subject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top