0

Good morning. I have an eletronic project in which I receive a variable from a RS232 device. That variable needs to be converted into an HEX type with their digits separated by a space in pairs, for example like the following structure: "12 42 15 54"

 public static void main(String[] args) {
            int ch = -1;
            String chave = "";
            while(ch != 'Q') {
              ch = inStream.read();
              if (ch >= 0) {
                outStream.write(ch);
                System.out.print((char)ch);  
                String hexch = Integer.toHexString(ch);
                System.out.print(hexch);


              }
          }

The code I used to convert into Hex is commentated but basically I want to rebuild the way I store the "ch" variable. I need the project to be compiled via JDE 1.3 so that is stricting my options. I researched in the forum but I couldn't find the answer.

Thanks!

kohhworlwide
  • 45
  • 1
  • 9
  • in which way the commented code did not meet your expectations? – Timothy Truckle Oct 17 '16 at 08:33
  • Instead of just pasting parts of your program, you'd greatly help those who might want to answer by providing [a minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). –  Oct 17 '16 at 08:52
  • Basically the Hex string comes assembled together and I want it separated because that will be the necessary format for my device! – kohhworlwide Oct 17 '16 at 08:53
  • See [this question](http://stackoverflow.com/questions/2297347/splitting-a-string-at-every-n-th-character). –  Oct 17 '16 at 09:27
  • They are all valid ways to do it, except for the fact that I need the solution to be compiled in 1.3 JDE. Forgot to mention that information, gonna add it to the question. Thanks for your answer in advance. – kohhworlwide Oct 17 '16 at 09:52

0 Answers0