You Are Here:

Community: Developer Discussion Boards

#1 Old OTT format vs. Java bytes. - 2004-06-08, 17:52

Join Date: Jun 2004
Posts: 4
markdb
Offline
Registered User
Hi,
forgive me if I'm being stupid or this
has been asked before :

Java only has signed bytes, which store
a maximum value of +127.

The Nokia MIDI to OTT converter outputs
a series of bytes, which are often above
127 (7F in hex). (Eg D1 and
95, which always appear in the OTT
header.)

One of the converter's output choices is
the code for a byte array, with these invalid values in it - this isn't valid Java!
The compiler doesn't complain about the
array definition, but try manually
assigning one of the high values from the
array to a byte variable later in the code;
You'll get a "loss of precision" error.

Please set me straight here - why does the converter produce byte values which java can't represent?
Reply With Quote

#2 Old 2004-06-09, 06:00

Join Date: Mar 2004
Posts: 19
Location: Australia
walkal
Offline
Registered User
I think the explanation is that a byte with the leading bit set to 1 is a valid representation of a negative number, coded according to the twos-complement scheme. You can set a byte variable to such a value by casting an integer or a short to a byte. E.g.

byte b = (byte)0xd1;

The cast just removes the leading zeroes. If you then do a println on b, you will see it interpreted as a negative number (-47 in this case).

If you have a tone sequence stored as a string - e.g. 024a3a40... - you can convert it to bytes by doing something like this:

for (int i = 0; i < toneString.length(); i += 2) {
oneByte = toneString.substring(i, i + 2);
outStream.writeByte((byte)Short.parseShort(oneByte, 16));
}

There may well be a less cumbersome way of doing this, but this is one method that works.


Alan Walker
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ