2

Let's say I have an array of Bytes

val base = [-2, 50, 48]

and I converted this array of Bytes to an array of Strings

val baseConverted = ["-2","50","48"]

Is there a way to convert 'baseConverted' back to 'base'?

2 Answers 2

3

You just need to use toByte from a String on every element:

List("-2","50","48").map(_.toByte)
Sign up to request clarification or add additional context in comments.

1 Comment

So simple yet I got stuck on that for over a week. Thanks a lot!
0

Here is how one can do it using Array:

val baseConverted = Array("-2", "50", "48")

val backToBase = baseConverted.map(_.toByte) 

// Prints
// backToBase: Array[Byte] = Array(-2, 50, 48)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.