Skip to content

Berry - Convert symbol to Berry escape format #22691

Answered by sfromis
valdus2 asked this question in Q&A
Discussion options

You must be logged in to vote

What you need is not so much a Berry escape sequence, but instead converting from UTF-16 to UTF-8 encoding. In this case, that could be p1b2.text='\xEE\x84\x9D' (3 bytes with hex escapes)

If you do not love bit-twiddling, you could also do the conversion using a bit of Berry code, something like this:

def int16_to_utf8(codePoint)
  var b = bytes(-3)
  b.set(0, 0xe0 | (codePoint >> 12 & 0x0f))
  b.set(1, 0x80 | (codePoint >> 6 & 0x3f))
  b.set(2, 0x80 | (codePoint & 0x3f))
  return b.asstring()
end
p1b2.text=int16_to_utf8(0xE11D)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@valdus2
Comment options

@sfromis
Comment options

@valdus2
Comment options

Answer selected by valdus2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants