# Rosetta Challenge! -- Reverse a String

**URL:** https://discourse.processing.org/t/rosetta-challenge-reverse-a-string/20644
**Category:** Coding Questions
**Created:** [May 8, 2020, 7:34pm UTC](https://discourse.processing.org/t/rosetta-challenge-reverse-a-string/20644 "2020-05-08T19:34:09Z")
**Posts on this page:** 1
**Showing post:** 23

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [May 10, 2020, 10:37am UTC](https://discourse.processing.org/t/rosetta-challenge-reverse-a-string/20644/23 "2020-05-10T10:37:55Z")

</div>

In order to better understand what is happening, I started to solve the [UTF-8 encode and decode](http://rosettacode.org/wiki/UTF-8_encode_and_decode) related to this task.  
The task is :

 ![good](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/20320490d7e84d167d8a9cfe47343bf1c718e854.jpeg)  
My working stage is: ![wrong](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/88a70aa29563524323eff6bc2bbad4d810e807da.jpeg)  
Where I ran again in problems because the last one is also a combined character.  
I can´t believe this isn’t possible in java. It must be possible at byte level.

```auto
import java.nio.charset.StandardCharsets;
import java.util.Formatter;
int t = 50; 
int tel;

Character[] chars = {'A', 'ö', 'Ж', '€', '?'}; // I changed last character because "\u1D11E" the Musical Symbol G Clef
                                               // can't be displayed in the editor it gives the errot "Invalid character constant "

void setup() {
  size(740, 200);
  background(255);
  fill(0);
  textSize(15);
  text("Character Name Unicode UTF-8 encoding (hex)", 25, 30);
  text("-------------------------------------------------------------------------------", 25, 50);
  for (int codepoint : new int[]{0x0041, 0x00F6, 0x0416, 0x20AC, 0x1D11}) {
    byte[] encoded = utf8encode(codepoint);
    Formatter formatter = new Formatter();
    for (byte b : encoded) {
      formatter.format("%02X ", b);
    }
    String encodedHex = formatter.toString();
    int decoded = utf8decode(encoded);
    println(decoded);
    t += 25;    
    text(chars[tel], 30, t); 
    text(Character.getName(codepoint), 130, t);
    text("U+"+hex(chars[tel]), 450, t);
    text(encodedHex, 550, t);
    tel++;
  }
}

final byte[] utf8encode(int codepoint) {
  return new String(new int[]{codepoint}, 0, 1).getBytes(StandardCharsets.UTF_8);
}

int utf8decode(byte[] bytes) {
  return new String(bytes, StandardCharsets.UTF_8).codePointAt(0);
}

```

---

_[View the full topic](https://discourse.processing.org/t/rosetta-challenge-reverse-a-string/20644)._
