Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:55:50+00:00 2026-05-26T14:55:50+00:00

Is it possible to convert a string to a byte array and then convert

  • 0

Is it possible to convert a string to a byte array and then convert it back to the original string in Java or Android?

My objective is to send some strings to a microcontroller (Arduino) and store it into EEPROM (which is the only 1  KB). I tried to use an MD5 hash, but it seems it’s only one-way encryption. What can I do to deal with this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:55:50+00:00Added an answer on May 26, 2026 at 2:55 pm

    I would suggest using the members of string, but with an explicit encoding:

    byte[] bytes = text.getBytes("UTF-8");
    String text = new String(bytes, "UTF-8");
    

    By using an explicit encoding (and one which supports all of Unicode) you avoid the problems of just calling text.getBytes() etc:

    • You’re explicitly using a specific encoding, so you know which encoding to use later, rather than relying on the platform default.
    • You know it will support all of Unicode (as opposed to, say, ISO-Latin-1).

    EDIT: Even though UTF-8 is the default encoding on Android, I’d definitely be explicit about this. For example, this question only says “in Java or Android” – so it’s entirely possible that the code will end up being used on other platforms.

    Basically given that the normal Java platform can have different default encodings, I think it’s best to be absolutely explicit. I’ve seen way too many people using the default encoding and losing data to take that risk.

    EDIT: In my haste I forgot to mention that you don’t have to use the encoding’s name – you can use a Charset instead. Using Guava I’d really use:

    byte[] bytes = text.getBytes(Charsets.UTF_8);
    String text = new String(bytes, Charsets.UTF_8);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do you convert Byte Array to Hexadecimal String, and vice versa,
Possible Duplicate: .NET String to byte Array C# How do I convert String to
Possible Duplicate: How do you convert Byte Array to Hexadecimal String, and vice versa,
Possible Duplicate: How to convert hex to a byte array? I'm searching for a
Is it possible to convert String to TreeNode in java Swing? If yes, how?
Possible Duplicate: How to Convert Byte* to std::string in C++? I'm on an embedded
Possible Duplicate: Is there an easy way to convert String to Inetaddress in Java?
Possible Duplicate: Convert string to Pascal Case (aka UpperCamelCase) in Javascript I'm doing some
Possible Duplicate: Convert string to float in Objective-C I'd like to convert a string
Possible Duplicate: Java AES Encrypt Entire String Im having problems with the conversions back

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.