LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2009, 02:24 PM   #1
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Rep: Reputation: 34
big endian


I'm trying to read about midi files here:
http://www.sonicspot.com/guide/midifiles.html

It says in Big endian C8 is 11001000

So I guess 1000 is 8 and 1100 is C.

If I fill out all 4 digit binary numbers that makes sense
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

So what is big endian? I don't get it. I keep reading it has to do with the most significant bit. I was using little endian then how would my 16 numbers above read?
 
Old 11-23-2009, 02:35 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by icecubeflower View Post
It says in Big endian C8 is 11001000
C8 hex is always 11001000 binary.

It is written in text with the most significant part on the left.

Big endian means most significant part first, while little endian means least significant part first.

If you can't understand the big difference between "on the left" and "first", you're going to be a little confused here.

In English we read left to right, so we think left is first. Inside a computer left and right don't have that kind of meaning.

Quote:
So what is big endian? I don't get it. I keep reading it has to do with the most significant bit.
Next trick is figuring out what "part" means. Big endian means the most significant part first. But it is ambiguous about what "part" means.

In that midi file document, "part" means "byte". They are not telling you the sequence of bits within a byte. They are telling you the sequence of bytes within any multi byte quantity.

Quote:
I was using little endian then how would my 16 numbers above read?
By "read" you are pulling in a "left to right" component that only leads to confusion in this topic.

You also are looking at just half a byte at a time. Serial (bit at a time) transfer and storage of data in and between computers is normally little endian regarding the sequence of bits within each byte. But that level (such as transferring bits on the SATA cable between the disk and the ram) is almost entirely transparent to the level of programming MIDI files.

So if you insist on left == first then to describe bit level little endian, you would need to write the four digits of each of your binary numbers backwards. I prefer the view that says you write them exactly as you have but read them starting at the right.

But all of the bit level sequence is a nearly pointless side question, because that MIDI spec is just talking about byte sequence. The bit sequence within a byte is whatever is natural to the computer you are on.

Last edited by johnsfine; 11-23-2009 at 02:54 PM.
 
Old 11-23-2009, 02:42 PM   #3
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Original Poster
Rep: Reputation: 34
I don't get it.
 
Old 11-23-2009, 02:49 PM   #4
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Original Poster
Rep: Reputation: 34
Well in the link it says the biggest value that can be represented by 4 bytes is 0x0FFFFFFF so it looks like we lose half a byte. I'd think the biggest value would be 0xFFFFFFFF. So if the 1st bit tells whether there is another byte of information then I guess it can't be part of the actual number?

So I think 01111111 is the largest byte and then if you had 11111111 then that would make no sense by itself because it means there is another byte coming.

Or maybe I'm completely wrong I don't know.
 
Old 11-23-2009, 03:21 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by icecubeflower View Post
Well in the link it says the biggest value that can be represented by 4 bytes is 0x0FFFFFFF so it looks like we lose half a byte.
It talks about variable length formats saying
Quote:
Variable-length values use the lower 7 bits of a byte for data and the top bit to signal a following data byte.
So obviously in any variable length data you lose one bit per byte, so you lose four bits from four bytes. What is difficult about that?

Notice also they say "lower 7 bits" and "top bit". They don't say "first" or "last" bits. At least in that section the writer was careful over the fact that they are not saying anything about the sequence of bits in a byte.

Quote:
if the 1st bit tells whether there is another byte of information then I guess it can't be part of the actual number?
Top bit not 1st bit. But otherwise, yes. The bit that tells you whether another byte follows is not part of the encoded number.

Last edited by johnsfine; 11-23-2009 at 03:23 PM.
 
Old 11-23-2009, 04:31 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
http://en.wikipedia.org/wiki/Endianness
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] A question about big-endian little-endian and how it affects things joeBuffer Programming 12 08-20-2009 01:02 PM
small-endian to big-endian conversion of data to store in a structure NancyT Programming 2 11-26-2008 10:06 AM
problem in understanding little endian/big endian machine program indian Programming 6 04-19-2006 02:50 PM
What is all this big endian-little endian stuff about? vdemuth Linux - Newbie 1 04-28-2004 02:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration