Archive

Posts Tagged ‘programmierung’

Convert Gray-Code to decimal/binary and back

February 16th, 2009 admin No comments

Gray-Code is a binary code developed by Frank Gray in 1947. It is used by most absolute incremental encoders and some favor it's use for fringe projection systems that have to encode the pixel data in a series of image patterns (mostly fringes with differing widths). To convert Gray-Code from and to Decimal numbers using c++ i had to look up different approaches with varying difficulty levels. I then compiled the following algorithms, that i will be using for my own fringe projection system (keep tuned).

It's rather easy if you know how to do it. I had to find out the hard way, so here's for the rest of the world:

First the easy part: transforming a integer number dec into a Gray-code _code:

C++:
  1. void _calculateGrayCode () {
  2.     bitset<numeric_limits<int>::digits + 1> bs(dec);
  3.     bitset<numeric_limits<int>::digits + 1> gs(dec);
  4.     bitset<numeric_limits<int>::digits + 1> _code(0);
  5.     bs>>= 1;
  6.     gs ^= bs;
  7.     for (unsigned i=0; i<_code.size(); i++){
  8.         _code[i] = gs[i];
  9.         gs[i]=0;
  10.     }
  11. }

Now to the part of converting Gray-Code to binary and then decimal number: Suppose our Gray-code is inside the bitset _code.

C++:
  1. void _calculateNumber () {
  2.     bitset<numeric_limits<int>::digits + 1> gs(0);
  3.     bitset<numeric_limits<int>::digits + 1> bs(0);
  4.     for (unsigned i=0; i<_code.size(); i++){
  5.         gs[i] = _code[i];
  6.     }
  7.     bs[gs.size()-1] = gs[gs.size()-1];
  8.     for (int i=gs.size()-2; i>=0;i--){
  9.         bs[i]=bs[i+1];
  10.         bs[i]=bs[i]^gs[i];
  11.     }
  12.     _number = static_cast<int>(bs.to_ulong());
  13. }

bs holds the binary representation of the Gray-Code and _number is the decimal respresentation.

References:

Erste Version von wp-stattraq veröffentlicht

August 11th, 2008 admin No comments

Eben gerade habe ich die erste neue Version von wp-stattraq auf wordpress.org freigegeben. Ich habe das Plugin nur insoweit verändert, als ich es für wordpress 2.6 lauffähig gemacht habe und dabei die Ausgabe des Plugins in die normale Administrationsobefläche integriert habe.

Später möchte ich noch einige Mankos des Plugins (die ich als langzeitiger Nutzer gut kenne) beseitigen. Aber vorerst müssen einige Integrationsprobleme (wie die automatische Installation bereinigt werden).

Wer Änderungswünsche und -vorschläge hat, sollte diese bitte direkt im trac-system als ticket eintragen:

http://trac.toomuchcookies.net/trac/wiki

Auch in Planung (code ist eigentlich schon fertig) ist ein plugin, das bei der seo-optimierung helfen soll und das soll die Daten von wp-stattraq nutzen. Dazu später mehr..