473,395 Members | 1,639 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,395 software developers and data experts.

Help assigning value to byte data type...

jeffbroodwar
118 100+
Hello, i have a problem about assigning a char value to a byte... please check the code below :

================================================== ======
Scenario # 1 : This code doesn't work :

byte[] buffer = new byte[256];
char tempValue;
int StartAddress;

buffer[StartAddress] = tempValue;

ERROR : possible loss of precision
explanation : if i try to save a char variables value to byte,i get the error message above....

================================================== =======


================================================== ======
Scenario # 2 : This code doesn't work :

byte[] buffer = new byte[256];
int StartAddress;

buffer[StartAddress] = '10';

ERROR : unclosed character literal bla bla bla bla
explanation : if i try to save a char value composed of 2 characters to byte,i get the error message above....

================================================== =======


================================================== ======
Scenario # 3 : This code works :

byte[] buffer = new byte[256];
int StartAddress;

buffer[StartAddress] = '2';

explanation : if i try to save a char value composed of 1 character to byte,i dont get any error. but the problem is i need to make Scenario # 1 work. what i need is to save the content of character Ex: charVariable = Microsoft to this array of bytes using charAt........ i cant make it work using charAt... it seems that it's looking for the ' ' symbols before and after the character values..... please help. thanks in advance..
================================================== =======
Jun 6 '07 #1
4 3303
r035198x
13,262 8TB
Hello, i have a problem about assigning a char value to a byte... please check the code below :

================================================== ======
Scenario # 1 : This code doesn't work :

byte[] buffer = new byte[256];
char tempValue;
int StartAddress;

buffer[StartAddress] = tempValue;

ERROR : possible loss of precision
explanation : if i try to save a char variables value to byte,i get the error message above....

================================================== =======


================================================== ======
Scenario # 2 : This code doesn't work :

byte[] buffer = new byte[256];
int StartAddress;

buffer[StartAddress] = '10';

ERROR : unclosed character literal bla bla bla bla
explanation : if i try to save a char value composed of 2 characters to byte,i get the error message above....

================================================== =======


================================================== ======
Scenario # 3 : This code works :

byte[] buffer = new byte[256];
int StartAddress;

buffer[StartAddress] = '2';

explanation : if i try to save a char value composed of 1 character to byte,i dont get any error. but the problem is i need to make Scenario # 1 work. what i need is to save the content of character Ex: charVariable = Microsoft to this array of bytes using charAt........ i cant make it work using charAt... it seems that it's looking for the ' ' symbols before and after the character values..... please help. thanks in advance..
================================================== =======
char is wider than a byte.
Read the first 3 posts of this article.
Jun 6 '07 #2
jeffbroodwar
118 100+
Hi, nice article you have there.... i actually saved it. ehehe. regarding that article.... why does java allow me to declare :

byte[] buffer = new byte[256];

if byte's maximum value is 127?




And can you help me with this problem?
- I need to save the character Ripple in byte array buffer[6] - buffer[35] the remaining bytes will be filled in with spaces... see code below

// Write spaces
for (int i=0; i<164; i++)
{
buffer[i] = 32;
}

(the decimal value 32's equivalent ascii character = space)
if Ripple word will consume indexes 6 - 11 then 12 - 35will remain as spaces(32)

all i need to do is save each character of Ripple saved inside the variable CompanyName to indexes 6 - 11. please take a look at the source below :

buffer[i]= 'R';
System.out.println("Result saved R value is: " + buffer[i]);
The printed value is 82.

you see, i can't find a way to save this character one by one placing each character inside the ' ' symbols. placing each character in the variable company insid the ' ' symbols gives me the headache....... the bottom line is :

buffer[6] = 82
buffer[7] = 105
buffer[8] = 112
buffer[9] = 112
buffer[10] = 108
buffer[11] = 101

each array from 6 -11 index will have the decimal values of characters Ripple


I hope i'm not asking too much sir, but i know my next question is just a very basic question to you.... hope you'll be patient enough to help me with all of these ^^;

- My next question is about the java file....

1. i can't make the jar file run without typing java - jar in the command line i have a sample program i created before that runs without java -jar... just the .jar file
2. can i make the .jar file run without the dist folder? just like the .exe files?
3. i can't display the hello world (WTF?? very basic eh? ehehe..^^; ) in the dos prompt using javac Main.java then java Main (an error occurs saying : Exception in thread "main" java.lang.UnsupportedClassVersionError : Main <Unsupported major.minor version 50.0>

LAST OF ALL : can i add you as my buddy here? so that i'll just ask questions directly to you..... cause sometimes it takes weeks before i get an answer and to top it all up, all i get is a WRONG one / just a comment. since your good with java, i guess you can be my java guru.... ehehe please? thanks
for being nice.... take care !


Best Regards,
Jeff
Jun 7 '07 #3
r035198x
13,262 8TB
.... why does java allow me to declare :

byte[] buffer = new byte[256];

if byte's maximum value is 127?
127 is the maximum size for a byte not for a byte[].
Arrays can be as long as the maximum int value (since array.length returns an int).





And can you help me with this problem?
- I need to save the character Ripple in byte array buffer[6] - buffer[35] the remaining bytes will be filled in with spaces... see code below

// Write spaces
for (int i=0; i<164; i++)
{
buffer[i] = 32;
}

(the decimal value 32's equivalent ascii character = space)
if Ripple word will consume indexes 6 - 11 then 12 - 35will remain as spaces(32)

all i need to do is save each character of Ripple saved inside the variable CompanyName to indexes 6 - 11. please take a look at the source below :

buffer[i]= 'R';
System.out.println("Result saved R value is: " + buffer[i]);
The printed value is 82.

char is wider than byte. If you want to manipulate chars just use a char[]



- My next question is about the java file....

1. i can't make the jar file run without typing java - jar in the command line i have a sample program i created before that runs without java -jar... just the .jar file
2. can i make the .jar file run without the dist folder? just like the .exe files?
3. i can't display the hello world (WTF?? very basic eh? ehehe..^^; ) in the dos prompt using javac Main.java then java Main (an error occurs saying : Exception in thread "main" java.lang.UnsupportedClassVersionError : Main <Unsupported major.minor version 50.0>
The point of making a .jar is so that you run it as you would a .exe. Read the jar files tutorial here and see how to make them effectively.

You seem to have a JDK that is newer than your JRE.


P.S All java forum posters are buddies. If you get any problem just post here in the forums where all your buddies will be able to help.
Jun 7 '07 #4
jeffbroodwar
118 100+
ok, thanx............................
Jun 8 '07 #5

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

Similar topics

9
by: Darren | last post by:
Hi wondering if anyone can help. What i'm trying to do is get a company from a MSSQL database with the COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to reference it to...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
4
by: TRW1313 | last post by:
I'm looking to populate a byte array of some fixed size to send out over a UDP connection. The data in the byte array is mixed between characters and binary. I'm a beginner to this language. ...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
2
by: Sisnaz | last post by:
I'm reading byte information from a C++ program via TCP sockets. At one time I thought I came across away to convert C Float data type into a VB single data type. I'm reading the C data type in...
3
by: cuties | last post by:
Hi all.... i'm very new to this programming language. i'm required to fulfill this task in the company i'm doing my practical. i hope i can get guide for my problem... Here is the script i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.