The Artima Developer Community
Sponsored Link

Java Answers Forum
Casting or Conversion char to byte[]

1 reply on 1 page. Most recent reply: Jul 9, 2005 10:49 AM by Antonio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Sreenivas Mangasandra

Posts: 2
Nickname: sreenivas
Registered: Jul, 2005

Casting or Conversion char to byte[] Posted: Jul 8, 2005 6:01 PM
Reply to this message Reply
Advertisement
Hallo Everybody

Could anyone tell how can i convert a char into a byte[] array.

For example :

1. byte echoMessage[]={'e'};

2. char dt = 'e';
byte bt[]=dt.getBytes();

Error says

char cannot be dereferenced
byte bt[] = dt.getBytes();
^
I could use Strings to convert from char to byte, but it then changes the format of the byte array, so what should i do?

Sreenivas


[ mksreenivas ]


Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: Casting or Conversion char to byte[] Posted: Jul 9, 2005 10:49 AM
Reply to this message Reply
What's the problem?
Why don't you just do
    char dt = 'e';
    byte bt[] = { (byte)dt };

?

Flat View: This topic has 1 reply on 1 page
Topic: IDE for JDK 1.5 Previous Topic   Next Topic Topic: How can I know the numlock key has been pressed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use