1. Hexadecimal and whatever...

Okay. I get this BRILLIANT idea and decide to star reading bytes from files.
I need to make it a number, so I use bytes_to_int to change a set of four bytes.
Truth is, I'm seeing if I can read data in from a MIDI file (don't ask me
why), and I read in the integer 101053452 (well, not exactly), but I'm
supposed to get the hexadecimal 00000006. Anyways, I think the problem is
that I need to read the bytes directly into hexadecimal. Anyone know how to
do that?

P.S. Anyone know what I'm talking about?

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The Reaper  (J. Lays)   http://www.geocities.com/TimesSquare/Alley/4444/
reaper at auracom.com      Check out my Euphoria Games page at:
            -= http://www.geocities.com/TimesSquare/Alley/4444/eugames.html
      ........................
     . .. -||..........__......  "There is a silence before a storm,
      . /  ||......../-- \\.::::  A calm that is spent in fear;
   . ..|   ||...... /    | |.:::  But if that time was spent running,
     .|  _-||.......||   / /.:::: There may be nothing to be afraid of."
    ..| |..||...... -\_- \ |\-.:::
     .| |.[< \ .../            \.::
      .||.|||\|\ |  -      - .  \.::::
     ...|.\|| |  \  |        |   |.:::.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

new topic     » topic index » view message » categorize

2. Re: Hexadecimal and whatever...

>Okay. I get this BRILLIANT idea and decide to star reading bytes from files.
>I need to make it a number, so I use bytes_to_int to change a set of four
bytes.
>Truth is, I'm seeing if I can read data in from a MIDI file (don't ask me
>why), and I read in the integer 101053452 (well, not exactly), but I'm
>supposed to get the hexadecimal 00000006. Anyways, I think the problem is
>that I need to read the bytes directly into hexadecimal. Anyone know how to
>do that?
>
>P.S. Anyone know what I'm talking about?
>
Heh, heh.  (<snicker, snicker>)
Ok, here's a possible solution.  Try it WITHOUT using bytes_to_int.
If you look at each of the 4 bytes that you combine into an integer (before you
combine them!) one of them should be equal to &H06 (hex value 6).

The problem is that 1 byte (8 bits) will hold 2^8 (256) values, ie &H00-&HFF.
If you combine 4 bytes (32 bits, and your basic integer type) you can now store
2^32 (4,294,967,292) values, or &H00-&HFFFFFFFF.
You want the hex value &H06 (00000006).  Since that is less than &HFF, it is
stored in a SINGLE byte, rather than a 4 byte integer.  When you combine the
four
bytes that you are reading, it makes a much larger value (10105342) than you
wanted.

Lets say that byte 1 = 00000006, byte 2 = 00000007, byte 3 = 00000001,
and byte 4 = 00000009. If we combine those we get &H06070109 ( i think) which
is a rather LARGE decimal number.

Anyway, just use each byte seperately rather than making an integer out of 4
of them.  Hope this helps.
James Powell

new topic     » goto parent     » topic index » view message » categorize

3. Re: Hexadecimal and whatever...

James Powell wrote:

> The problem is that 1 byte (8 bits) will hold 2^8 (256) values, ie &H00-&HFF.
> If you combine 4 bytes (32 bits, and your basic integer type) you can now stor
e
> 2^32 (4,294,967,292) values, or &H00-&HFFFFFFFF.
> You want the hex value &H06 (00000006).  Since that is less than &HFF, it is
> stored in a SINGLE byte, rather than a 4 byte integer.  When you combine the
> four
> bytes that you are reading, it makes a much larger value (10105342) than you
> wanted.

Maybe you could say that H06 could be stored in ANY amount of byte... example:
In 4 bytes: #00, #00, #06
In 2 bytes: #00, #06
.. etc...

In general you can say that the value of a number stored in several bytes is:

(byte1)+(byte2*256)+(byte3*256^2)+(byte4*256^3)+ ... +(byteN*256^N-1)
where byte1 is the least significant byte and byte N the most significant byte.
In the above examples:
(6)+(0*256)+(0*65536) = 6

> Anyway, just use each byte seperately rather than making an integer out of 4
> of them.

James is right... the number you've got 101053452 is in hexadecimal 06 05 F4 0C
which i interpret as been the right result for you to get EACH BYTE alone and
not trying to get 4 byte numbers (4 byte number = 2^32).

Hope this helps you, if you need more info about binary numbers just ask me, som
e
time ago I had the same troubles trying to understand how numbers where stored ;
)

Bye,
--

            ************************************
            This message sent by Daniel Berstein
            ************************************
     email: architek at geocities.com
 homepages: http://www.geocities.com/SiliconValley/Heights/9316
            http://www.cybercity.hko.net/silicon_valley/architek

new topic     » goto parent     » topic index » view message » categorize

4. Re: Hexadecimal and whatever...

At 16:57 97-04-15 -0400, you wrote:
>---------------------- Information from the mail header -----------------------
>Sender:       Euphoria Programming for MS-DOS <EUPHORIA at
>MIAMIU.ACS.MUOHIO.EDU>
>Poster:       The Reaper <reaper at LOKI.ATCON.COM>
>Subject:      Hexadecimal and whatever...
>-------------------------------------------------------------------------------
>
>Okay. I get this BRILLIANT idea and decide to star reading bytes from files.
>I need to make it a number, so I use bytes_to_int to change a set of four
bytes.
>Truth is, I'm seeing if I can read data in from a MIDI file (don't ask me
>why), and I read in the integer 101053452 (well, not exactly), but I'm
>supposed to get the hexadecimal 00000006. Anyways, I think the problem is
>that I need to read the bytes directly into hexadecimal. Anyone know how to
>do that?
>
>P.S. Anyone know what I'm talking about?
>


1) In MIDI file integer are stored in straigth order as opposed to the
inverted order used in PC. bytes_to_int() suppose that the first byte is the
least significant (INTEL style) in MIDI file the first byte is most
significant (MOTOROLA style), so bytes_to_int() will give a wrong result if
you use it to read MIDI file.


Jacques Deschenes
Baie-Comeau, Quebec
Canada
desja at quebectel.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Hexadecimal and whatever...

On Tue, 15 Apr 1997 20:09:36 -0400 Jacques Deschenes
<desja at QUEBECTEL.COM> writes:
>At 16:57 97-04-15 -0400, you wrote:
>
>>Okay. I get this BRILLIANT idea and decide to star reading bytes from
>files.
>>I need to make it a number, so I use bytes_to_int to change a set of
>four
>bytes.
>>Truth is, I'm seeing if I can read data in from a MIDI file (don't
>ask me
>>why), and I read in the integer 101053452 (well, not exactly), but
>I'm
>>supposed to get the hexadecimal 00000006. Anyways, I think the
>problem is
>>that I need to read the bytes directly into hexadecimal. Anyone know
>how to
>>do that?
>>
>>P.S. Anyone know what I'm talking about?
>>
>
>1) In MIDI file integer are stored in straigth order as opposed to the
>inverted order used in PC. bytes_to_int() suppose that the first byte
>is the
>least significant (INTEL style) in MIDI file the first byte is most
>significant (MOTOROLA style), so bytes_to_int() will give a wrong
>result if
>you use it to read MIDI file.
>
>Jacques Deschenes
>Baie-Comeau, Quebec
>Canada
>desja at quebectel.com
>

Jacques is right. :)
You should get help reading binary numbers.

To do this will require loading each number say a 2 byte number
1 byte at a time

the first byte, or byte1, is value
and the second byte, or byte2, is value*256
so the number is first+(second*256) OR

number = byte1 + (byte2 * 256)

NOTE: Paranthesis not needed.

DON'T take my word for it though.  Somebody check this for me.
I am a bit busy lately.

HOPE this helps.

--Lucius Lamar Hilley III
--  E-mail at luciuslhilleyiii at juno.com
--  I support transferring of files less than 60K.
--  I can Decode both UU and Base64 format.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Hexadecimal and whatever...

re: reading MIDI files

Before going into details, let me suggest that you use the freeware program
T2MF and MF2T (text to midi file/midi file to text) that's posted somewhere
on the internet. If you can't find it, I could probably e-mail it to you.

You are partly correct. You need to read the numbers as bytes. However, MIDI
files store *some* it it's numbers in an irritating number compression
scheme, where the high bit of the number indicates if the next byte is part
of the number. That means that only 7 of the 8 bits of that number are
"real", and the 8th bit is a "continuation" bit. This is done because MIDI
was designed to flow over slow (but cheap) serial lines.

So if you read the byte:

    01h = 00000001

you would use the low bits as the number data:

    0000001

and the high bit as a flag indicating if the number continues on to the next
byte (in this case, it does not). The number in this case is 01h.


Of course, it's typically more complex than this. If you read the byte:

    ADh = 10101101

then you would have the 7 low bits of the number:

    0101101

and note that the 8th bit is set, meaning you need to append the following
byte to the number. If the next byte were:

    1Fh = 10001111

then you would take the 7 low bits:

    0001111

as the high part (bits 8-14) of your accumulated number:

    00011110101101

But since the 8th but of the byte is on, you need to append the *next* byte,
also:

    01h = 00000001

Again, bits 1-7 are data:

    0000001

These are appended to the high part (15-21) of your number:

    000000100011110101101


and bit 8 if the byte is finally 0, so you've completely read the byte.
Breaking it up into bytes, we get:


    00000 01000111 10101101
    00h   87h      ADh
    87ADh
    34733d

If you had simply glommed the bytes together, you would have gotten
something like:

    011FADh = 73645

which is *way* wrong. Besides which, if you didn't pay attention to the
"continuation" bit, you probably would have read in *four* bytes, and gotten
an even *more* bogus number, and set your pointer to the wrong file
position.

Remember that not all the numbers in a MIDI file are compressed - you'll
need to consult the specs on which is which.

Trying to create a MIDI file is even more irritating, because you have to
create the entire track before you can write it, since (1) the size of the
track in included in the header, and (2) you can't calculate the size of the
track until you create it, because the data is compressed.

I didn't have time to look any of the above up, but you can read all about
it in the MIDI File specs, posted all over the internet. Again, I'd
recommend MF2T/T2MF, especially since it makes it easier to debug your
program's output - you can edit your input/output as plain text. That's what
I use to generate my computer-composed music with.

If you want, I think I can dig up one of my buggy programs at home in QBASIC
or Euphoria that tries to read MIDI files. Once you are past the number
compression, though, everything else is pretty simple.

 -- David Cuny

new topic     » goto parent     » topic index » view message » categorize

7. Re: Hexadecimal and whatever...

At 11:21 AM 4/16/97 PST, you wrote:
>---------------------- Information from the mail header -----------------------
>Sender:       Euphoria Programming for MS-DOS <EUPHORIA at
>MIAMIU.ACS.MUOHIO.EDU>
>Poster:       "Cuny, David" <ATB.DCUNY at HW1.CAHWNET.GOV>
>Subject:      Re: Hexadecimal and whatever...
>-------------------------------------------------------------------------------
>
>re: reading MIDI files
>
>Before going into details, let me suggest that you use the freeware program
>T2MF and MF2T (text to midi file/midi file to text) that's posted somewhere
>on the internet. If you can't find it, I could probably e-mail it to you.

I can't seem to find it, but it sounds good. Could you send it my way?

> (Lots of info...)

Whoah! I figured I was outta my league. However, I have been able to get a
few numbers out of it, until a hit a 16-bit "word" which has a number for
every bit.
I am using the specs, which gave me the idea of trying this crazy idea in
the first place.

>If you want, I think I can dig up one of my buggy programs at home in QBASIC
>or Euphoria that tries to read MIDI files. Once you are past the number
>compression, though, everything else is pretty simple.

Trust me, I can use all the help I can get. By the way, thanks to everybody
who sent help to me. It was really useful. By the way, Deschene, the fact
that the numbers are stored significant byte first doesn't really matter
because that's the way I want to read them anyways (why do I get the feeling
I'm going to regret saying that?). If I actually come up with something,
I'll be sure to tell all of ya.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The Reaper  (J. Lays)   http://www.geocities.com/TimesSquare/Alley/4444/
reaper at auracom.com      Check out my Euphoria Games page at:
            -= http://www.geocities.com/TimesSquare/Alley/4444/eugames.html
      ........................
     . .. -||..........__......  "There is a silence before a storm,
      . /  ||......../-- \\.::::  A calm that is spent in fear;
   . ..|   ||...... /    | |.:::  But if that time was spent running,
     .|  _-||.......||   / /.:::: There may be nothing to be afraid of."
    ..| |..||...... -\_- \ |\-.:::
     .| |.[< \ .../            \.::
      .||.|||\|\ |  -      - .  \.::::
     ...|.\|| |  \  |        |   |.:::.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

new topic     » goto parent     » topic index » view message » categorize

8. Re: Hexadecimal and whatever...

At 21:06 97-04-16 -0400, you wrote:
> By the way, Deschene, the fact
>that the numbers are stored significant byte first doesn't really matter
>because that's the way I want to read them anyways .
> why do I get the feeling I'm going to regret saying that?).

I don't known Lay.


Jacques Deschenes< do you see the "s" I the end of my name? Or you written your
own mail reader. Sorry to tell you it drop some character.


P.S. If your name miss an "S" it's probably your mail reader that drop it.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Hexadecimal and whatever...

At 10:31 PM 4/16/97 -0400, you wrote:

>I don't known Lay.
>Jacques Deschenes< do you see the "s" I the end of my name? Or you written your
>own mail reader. Sorry to tell you it drop some character.
>P.S. If your name miss an "S" it's probably your mail reader that drop it.

Ha.
Stop using my real name.
Especially if you're going to trash it  :)

You guys just won't let me make a mistake, will you?  :(

"There is no field as empty
 As a sea of people who,
 Even in the darkest times,
 Will not shine the lights of forgivness."

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The Reaper  (J. Lays)   http://www.geocities.com/TimesSquare/Alley/4444/
reaper at auracom.com      Check out my Euphoria Games page at:
            -= http://www.geocities.com/TimesSquare/Alley/4444/eugames.html
      ........................
     . .. -||..........__......  "There is a silence before a storm,
      . /  ||......../-- \\.::::  A calm that is spent in fear;
   . ..|   ||...... /    | |.:::  But if that time was spent running,
     .|  _-||.......||   / /.:::: There may be nothing to be afraid of."
    ..| |..||...... -\_- \ |\-.:::
     .| |.[< \ .../            \.::
      .||.|||\|\ |  -      - .  \.::::
     ...|.\|| |  \  |        |   |.:::.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu