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 8592043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:39:38+00:00 2026-06-11T23:39:38+00:00

I have String: String str = KITTEN; And I would like to make a

  • 0

I have String:

String str = "KITTEN";

And I would like to make a byte[] from it, but just:

byte[] mybyte = new byte[] { 'K', 'I', 'T', 'T', 'E', 'N'}

Anyone knows how to change String to that byte[]? Everything what I can find is about actual converting – please note that I don’t want to have hex representation of string.

PS. Title of question may be wrong – I’m sorry for that, didn’t know how to write it.

EDIT:

byte[] myBytes = str.getBytes();

Displaying:

byte[] display = new byte[] { 0x00, 0, 0, 'K', 'I', 'T'}; 

works, and displaying:

byte[] display = new byte[] {  0x00, 0, 0, myBytes[0], myBytes[1], myBytes[2] }; 

doesn’t work.
I try to display it on the screen of my device connected to the android phone by NFC. Do you know what’s make the problem?

  • 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-06-11T23:39:39+00:00Added an answer on June 11, 2026 at 11:39 pm

    getBytes() works for me:

    String str = "KITTEN";
    byte[] bytes = str.getBytes();
    for(byte b : bytes) {
        System.out.print("'" + (char) b + "' ");
    }
    
    'K' 'I' 'T' 'T' 'E' 'N' 
    

    Everything else what @Jon writes is still valid, as getBytes() is also doing a conversion:

    Encodes this String into a sequence of bytes using the platform’s
    default charset, storing the result into a new byte array.

    Since using getBytes() introduces some platform dependencies, you should better explicitly pass an appropriate Charset:

    byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supposed I have the following string: string str = <tag>text</tag>; And I would like
I have a string str = '${1:textbox}',[${2:x},${3:y},${4:w},${5:h}] and I would like to replace all
I have a string like: string str = https://abce/MyTest; I want to check if
I have a string like the following: String str = 4*5; Now I have
I have the following function: public static byte[] StringToByte(string str) { int length =
I have a string like this String str = la$le\\$li$lo . I want to
I have a string containing lots of text with white-spaces like: String str =
I have a string Str , that I read from a file. Its values
If I have this string str = 22px; How do I extract just the
I have a string like below string str = ABE,1A2B3CD,1B2A3C,1A2BC3E; How can i split

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.