Re: Hexadecimal and whatever...
- Posted by James Powell <Wizard at DJO.COM> Apr 15, 1997
- 883 views
>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