BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-25-2007, 01:01 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2006
Model: 8310
Carrier: AT&T (formerly Cingular)
Posts: 47
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to populate a byte array

Please Login to Remove!

I think this is a pretty simple question but I haven't been able to find the answer online.

I want to store the binary data for a MIDI file in my application in the form of a byte array. Since the MIDI file never changes and is only 168 bytes long I want to have it hard coded into a byte[] variable, rather than load it from a data stream.

I know how to create a byte array by doing
Code:
 
byte[] buffer = new byte[168]
but I'm not sure how to fill the array with data.

I guess it would look something like this? The MIDI data contains null characters also so I'm not sure how all that would be input into the array.
Code:
byte[] buffer = new byte[1, 2, 3, 4, 5]
Offline  
Old 02-25-2007, 01:53 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2006
Model: 8310
Carrier: AT&T (formerly Cingular)
Posts: 47
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I think I figured it out. I have to use the Hex values of each byte and populate the array. I kept searching and found a webpage.

I think it goes something like this.
Code:
byte[] midi = new byte[] {(byte)0x00, (byte)0x4F};

Last edited by forcedfx : 02-25-2007 at 02:07 PM.
Offline  
Old 02-26-2007, 04:41 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't have to use hex values, you just need the cast to a byte:

Code:
byte[] midi = new byte[] {(byte)1, (byte)2};
or

Code:
byte[] midi = new byte[5];
midi[0] = (byte)1;
midi[1] = (byte)2;
...
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.