tags:

views:

44

answers:

2

Hi,

I try to add a byte to an array like this:

messagedata.Add((byte)0xF0);

But then when I check the array, the item looks like 0xf0 but it since it's going to be a MIDI message I found it has to be a capital F. What can I do to keep the letters capitalized?

+3  A: 

It's not possible to keep the letter capitalized, because the letters aren't stored in the array. The only thing stored in the array is a numerical value, and 0xf0 is just one of the way to represent that value as text.

You don't need to keep the letter capitalized. A MIDI message is sent as bytes, not text, so 0xf0 and 0xF0 are textual representations of the same value. There are other ways to represent the same value as text, as 240, 0360 or %11110000, and they all mean the same thing.

This code:

messagedata.Add((byte)240);

produces the exact same result as your code above. The executable code will be identical, and it's not possible to determine which code was used by examining the compiled code.

Guffa
Thanks for the quick response. Seems the problem lies in something else: when an integer (for example 1) is converted, it results in 0x00 but I need 0x31... any advice?
internetmw
@internetmw: If you convert the integer value `1` into a byte, you will get a byte with the value `1`, or `0x01`. Pehaps you want to convert the character value `'1'` into a byte, which gives the value `49` or `0x31`.
Guffa
Thanks I'll look for some different conversion code then;)
internetmw
A: 

0xF0 and 0xf0 are the same thing. When you look and see 0xf0 (with a debugger or whatever) that tool simply decided to use lower case letters. F and f both mean 4 bits all equal to 1

pm100