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  
Closed Thread


Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

50PCS National NM24C02M8 Serial EEPROM 256 x 8 Bus Interface 8 Pin Plastic SOP
$12.5
50PCS National NM24C02M8 Serial EEPROM 256 x 8 Bus Interface 8 Pin Plastic SOP picture115 X MICROCHIP 24LC64-I/SN IC EEPROM 64KBIT 400KHZ 8SOIC
$46.9
115 X MICROCHIP 24LC64-I/SN IC EEPROM 64KBIT 400KHZ 8SOIC pictureOMRON ROM-H EEPROM Memory Chip with label
$17.0
OMRON ROM-H EEPROM Memory Chip with label picture10pcs New AT24C256 24C256 memory / serial EEPROM DIP8
$5.49
10pcs New AT24C256 24C256 memory / serial EEPROM DIP8 pictureAtmel AT24C64N-10SC 64Kbits eeprom SO 8 (lot of 10)
$2.0
Atmel AT24C64N-10SC 64Kbits eeprom SO 8 (lot of 10) picture






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