-2
  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?

Eveli
  • 498
  • 1
  • 6
  • 27
  • 2
    What do you really want to achieve? 30 decimal is not 10 hex, and 20 decimal is not 00 hex – Andreas Fester Feb 25 '13 at 14:59
  • I believe this is not the exact print out. – John Dvorak Feb 25 '13 at 14:59
  • You're converting integers to hex and use `int` variables to hold the result? How are you going to represent the "numbers" A to F? Additionally, what's the point of this line: `Integer.parseInt(Integer.valueOf(diny7).toString(), 10);`? Assuming `diny7` is a string, you then convert a string to an integer to a string to an integer - huh? – Thomas Feb 25 '13 at 15:00
  • sry, forgot to mention.. the incoming values are reduced by 20 – Eveli Feb 25 '13 at 15:00
  • there should be only numbers, no A - F – Eveli Feb 25 '13 at 15:00
  • Question about this kind of conversion was answeard [here](http://stackoverflow.com/questions/9321553/java-convert-integer-to-hex-integer) – Quirin Feb 25 '13 at 15:01
  • You convert `diny?` to `Integer`, then `toString`, then parse as decimal and save to `diny?h`. Where's the point in that? Do you expect `diny?h` to not ever be equal to `diny?`? – John Dvorak Feb 25 '13 at 15:01
  • @Jan Dvorak a good question oo i tried different ways, and this is where i gave up now... am dazzled... diny should be convertet from 30 to 10 – Eveli Feb 25 '13 at 15:03
  • @Quirin thx for link, but i already tried that – Eveli Feb 25 '13 at 15:04
  • 2
    What do you think the word "hex" means? Because as far as I can tell, nothing in your question has anything to do with hex. – ruakh Feb 25 '13 at 15:05
  • 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 30(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 – Eveli Feb 25 '13 at 15:11
  • I am eager to downwote any question containing a lot of garbage besides the main point of question. We are not going to do the math here adding and "reducing" anything. Debug your code yourself. – Val Feb 25 '13 at 15:31
  • thx val... people like you are the reason, why many people do not ask any question because they have to be afraight of being blamed – Eveli Feb 25 '13 at 21:49

2 Answers2

2

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.

yurib
  • 8,043
  • 3
  • 30
  • 55
  • okay, then theyre printed out as hex, but i need the numbers forupdating a textfield and do a little math. – Eveli Feb 25 '13 at 15:16
0

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

Eveli
  • 498
  • 1
  • 6
  • 27