Tips for

Contact me: dhalperi@cs.washington.edu

Back to Daniel Halperin's webpage.

MATLAB

Computing a CRC-32 in MATLAB
(a.k.a. CRC32, IEEE 802.3 FCS, IEEE 802.11 FCS, Ethernet FCS, WiFi FCS, 32-bit checksum)

Unfathomably, this code is hard (impossible?) to find online. (Hence the long line of a.k.a.'s above enabling Google to do its job.) There are lots of hyper-optimized C/C++/C# implementations using tables, but nothing useful for MATLAB. Here you go! (download link: crc32.m)

function ret = crc32(bits)
poly = [1 de2bi(hex2dec('EDB88320'), 32)]';
bits = bits(:);

% Flip first 32 bits
bits(1:32) = 1 - bits(1:32);
% Add 32 zeros at the back
bits = [bits; zeros(32,1)];

% Initialize remainder to 0
rem = zeros(32,1);
% Main computation loop for the CRC32
for i = 1:length(bits)
    rem = [rem; bits(i)]; %#ok<AGROW>
    if rem(1) == 1
        rem = mod(rem + poly, 2);
    end
    rem = rem(2:33);
end

% Flip the remainder before returning it
ret = 1 - rem;
end

Increasing Datatip Precision

By default, MATLAB only displays four digits of precision when using the Datatip tool in plots. This can be really irritating when you're trying to get an exact spot in a large file:

You can load an alternate datatip file every time you open a plot, or you can export the cursor data and then access the coordinates of that point inside the object in the command window, but I really wanted another way.

So I found the default datatip file and modified it myself.

This file has two lines of text reading:

I changed the 4's to 8's.

Subversion

Creating and using patches with SVN

SVN doesn't recognize my PDF/PS files as binary

For individual files, SVN will treat them as binary files if you mark their mime-type as application:

svn propset svn:mime-type application/pdf my.pdf

Or, you can set options for all files of a certain extension by editing ~/.subversion/config:

 [miscellany]
 enable-auto-props = yes                # enables SVN's automatic labelling
 [auto-props]
 *.pdf = svn:mime-type=application/pdf
 *.ps = svn:mime-type=application/ps

Preparing conference papers with latex/dvips/ps2pdf/pdflatex

ACM/IEEE camera ready process

OmniGraffle