473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to convert bytearray into char

Hi, i'm new in java and i wanna know how can i convert a bytearray into a char. Actually I need to take a data from a file (this file is written in a byte code, whose extensio is .dac) and to convert this data into a char.
Please help me, and I would like to ask to explain me step by step all the process, including if i will need to put any import im my program.


Thanks a lot.........andremarim
Jul 17 '07 #1
6 2887
blazedaces
284 100+
Hi, i'm new in java and i wanna know how can i convert a bytearray into a char. Actually I need to take a data from a file (this file is written in a byte code, whose extensio is .dac) and to convert this data into a char.
Please help me, and I would like to ask to explain me step by step all the process, including if i will need to put any import im my program.


Thanks a lot.........andremarim
Find a method that converts into a number (I'm assuming we're talking about unsigned) or make one yourself and then simply cast it as a char to convert it via ASCII...

Good luck,

-blazed
Jul 17 '07 #2
JosAH
11,448 Expert 8TB
Hi, i'm new in java and i wanna know how can i convert a bytearray into a char. Actually I need to take a data from a file (this file is written in a byte code, whose extensio is .dac) and to convert this data into a char.
Please help me, and I would like to ask to explain me step by step all the process, including if i will need to put any import im my program.


Thanks a lot.........andremarim
First a remark:

Read the "article index" post in the Java Articles section (see the menu bar
at the top of this page). At the end of that index is a link to the complete API
documentation for all the core classes. Download that documentation for regular
inspection and reading. You'll find detailed documentation there for every class
and method available in the core classes jar that comes with your JDK.

Second a question for you:

I don't understand your question: a char is just two bytes. You can't stick an
entire byte array in one single char. Care to rephrase your question?

kind regards,

Jos
Jul 17 '07 #3
First a remark:

Read the "article index" post in the Java Articles section (see the menu bar
at the top of this page). At the end of that index is a link to the complete API
documentation for all the core classes. Download that documentation for regular
inspection and reading. You'll find detailed documentation there for every class
and method available in the core classes jar that comes with your JDK.

Second a question for you:

I don't understand your question: a char is just two bytes. You can't stick an
entire byte array in one single char. Care to rephrase your question?

kind regards,

Jos
thanks guy. Actually I've already solved my problem. Cast worked fine.

But, let me try to explain you what was my problem because by doing this I show you a another problem that I've to solve.
in the first problem I had a file and in this file I'd to read a char codifyed in bytes. This is the why I needed to convert a bytearray into char.
Now my problem is to convert a float into to bytearray. because I've to put some float values into a external file.

Thanks a lot.

andremarim
Jul 17 '07 #4
blazedaces
284 100+
thanks guy. Actually I've already solved my problem. Cast worked fine.

But, let me try to explain you what was my problem because by doing this I show you a another problem that I've to solve.
in the first problem I had a file and in this file I'd to read a char codifyed in bytes. This is the why I needed to convert a bytearray into char.
Now my problem is to convert a float into to bytearray. because I've to put some float values into a external file.

Thanks a lot.

andremarim
Just so you know though, take a look at the Wrapper classes (Integer, Float, Double, etc.)... I believe they have methods to convert into byte arrays...

Ok, just went to check, yup, I was correct, here's the float class:

http://java.sun.com/j2se/1.3/docs/ap...ang/Float.html

And the method you want is the byteValue() method (the first one that you see).

Hope this helped,

-blazed

P.S. And here's the byte wrapper class, which I didn't know about: http://java.sun.com/j2se/1.4.2/docs/...lang/Byte.html

Which will transform a byte into specific types, though I don't know why they haven't already made this, if you use anything that's more then one byte, which is almost anything you'd need to shift and whatnot...

-blazed
Jul 17 '07 #5
THANKS very much.....I solved my problem, actually we solved my problem...........thanks again........
Jul 18 '07 #6
JosAH
11,448 Expert 8TB
THANKS very much.....I solved my problem, actually we solved my problem...........thanks again........
Only now I understand your problem. The answer screams for a ByteBuffer.
Check it out in the nio package.

kind regards,

Jos
Jul 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Prabhu | last post by:
Hi, I have to send a structure through TCPClient socket. we can send only byte array through the socket, So please any one can help me by telling How to convert a struct object into an byte...
1
by: War Eagle | last post by:
Is it possible to convert an unsigned long to byte array. For instance, unsigned long = 23480923 unsigned long longNumber; longNumber=23480923; // in binary = 1 0110 0110 0100 1010 0101 1011 //...
1
by: Jim | last post by:
Here is a snipet of the code. // State object for receiving data from remote device. public class StateObject { // Client socket. public Socket workSocket = null; // Size of receive buffer....
6
by: Allan Ebdrup | last post by:
How do I easily convert a int to a string? Kind Regards, Allan Ebdrup
6
by: Petar Popara | last post by:
I need some help converting byte into Array: int bufferLen = Convert.ToInt32(file.Length); byte buffer = new byte; int len = sr.Read(buffer, 0, bufferLen); ArrayList a = new ArrayList(len);...
1
by: Sergey Muschin | last post by:
Hi there, i need to send a socket message to TCP socket server. Server has been implemented with VC 6.0 and expects from client the message in this format typedef struct { int msg_nbr; ...
3
by: Asha | last post by:
greetings, i'm having trouble converting the below c# codes into vb.net, the other portion of it is working fine except this, cause i do not know how to convert it. any help provided would be...
1
by: gijamie911 | last post by:
int nBytes = 256; byte ByteArray = new byte; int nBytesRead = inputStream.Read(ByteArray, 0 , nBytes); recorderID = ""; for (int i...
4
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.