| «« An Intro to jid3rL | The id3v2 Frames Hierarchy »» |
|
About
I'm Ryan Lowe, a Software Engineering graduate living in Ottawa, Canada. I like agile software development and Ruby on Rails.
I write this blog in Canadian English and don't use a spell checker. Typos happen.
Projects
» Full-time Ruby on Rails freelancer
» Full-time with Rails since May 2005 » Former committer for RadRails (now Aptana) » I also have a few Rails side-projects in development: 1. wheretogoinTO.com Toronto nightlife 2. Hey Heads Up! TODO list and sharing 3. Layered Genealogy family history research 4. foos for foosball scoring 5. fanconcert for music fans (on hold) Hiring Rails developers? I can telecommute by the hour from Ottawa, Canada »» Email: rails AT ryanlowe DOT ca
BulletBlog
Now hosted on Hey! Heads Up -- check it out!
Syndication
Pings
Recent
Derek Lowe's (Ryan's older brother) words at Ryan's funeral
blog@ryanlowe.ca no more Forging Email Headers: Good, Bad or Ugly? Sarcastic Dictionary (Part 1 of Many) Tags Hierarchies Twisting Rails is Risky Business Risky Business? My Take on Early Alphas Whoa, it's August 2007 Closing Comments A Postscript to "Growth at the grassroots" »» All Blog Posts
Linkage
del.icio.us/ryanlowe
technorati/ryanlowe.ca/blog Aurora Roy Jim Andrew Trasker Travis Kibbee Karen Dr. Unk Ayana Van Bloggers Joel Spolsky Robert Scoble Tim Bray Dave Winer Raymond Chen James Robertson Ruby/Rails Bloggers rubyonrails.org weblog David Heinemeier Hansson Dave Thomas James Duncan Davidson Mike Clark Jamis Buck Signal vs. Noise Tobias Luetke Amy Hoy: (24)slash7 Jeremy Voorhis Eclipse Bloggers Planet Eclipse EclipseZone Luis de la Rosa Eclipse Foundation Kim Horne Billy Biggs Ian Skerrett Mike Milinkovich Bjorn Freeman-Benson Denis Roy
Archives
|
Java Signed Bytes and Decoding Flags
The id3v2 spec has bit flags in it, which are either 1/0 (true/false). These flags are jammed into bytes and each byte can contain up to eight flags. For example, here's an excerpt from the 2.3.0 spec for the tag header flags:
The Unsigned byte values range from 0 to 255. The most significant bit is on the left (a, worth 128 if on) and the least significant bit is on the right. If you don't know how to decode bits from an unsigned byte, you can read up on it. The problem is that Java represents bytes as signed bytes, which range from -128 to 127. I'm reading signed bytes from the files, so I have to deal with them. You might say "OK, just take the signed byte and add 128 to it to get an unsigned byte". At first glance that might seem correct, but it's not. To understand why you have to get under the hood of the Java signed byte. Java stores its signed bytes in two's complement notation. If only the The trick is to use a bitwise operator in Java that doesn't care about sign: the unsigned right shift operator
The How did I verify my code works? Unit testing, of course. Here are the tests I do: I could be much more comprehensive, especially on the negative side. But this seems good enough for now. Posted at August 09, 2004 at 08:30 AM ESTLast updated August 09, 2004 at 08:30 AM EST Comments
I ran into this exact same problem when doing the code for id3v1 for track number. It was the boundary cases that always show the problems since I only ran into the problem when I tried to give a mp3 a track number greater than 128 which isn't too common. » Posted by: Jim at August 9, 2004 12:15 PM
[Once I am done with this honeymoon stuff, I was going to jump on the .net fitnesse bandwagon - i'll let you know how it goes] » Posted by: dru at August 25, 2004 10:41 PMVery cool to be here. Hi all! » Posted by: at December 1, 2004 04:51 AMVery interesting. This info helped me a lot. |