Ge Wangcore ejectedd38351c9 years agoHistory
61 lines · 1.4 KB · C++
RawDownload
//-----------------------------------------------------------------------------// name: hex2cpp.cpp// desc: hexdump to cpp//// author: Ge Wang (gewang@cs.princeton.edu)//   data: Summer 2004//-----------------------------------------------------------------------------#include <iostream>#include <sstream>#include <stdio.h>#include <limits.h>using namespace std;  // one of these days i will learn perl, or awk, or sedint main( int argc, char ** argv ){    if( argc < 2 )    {        cerr << "hex2cpp: too few arguments..." << endl;        exit( 1 );    }     string line;    int count = 0;    cout << "// data for " << argv[1] << ".raw..." << endl;    cout << "SAMPLE " << argv[1] << "_data[] = {" << endl;     while( getline( cin, line ) )    {        istringstream sin( line );        string token, token2;        int c = 0;        short x = 0;         // get rid of offset        sin >> token;        cout << "    ";         while( sin >> token >> token2 )        {            x = (token2[0]-'0')*64 + (token2[1]-'0')*8 + (token2[2]-'0');            x <<= 8;            x += (token[0]-'0')*64 + (token[1]-'0')*8 + (token[2]-'0');            printf( "%.1ff,", (float)x );            count++;            c++;        }         if( c )            cout << endl;    }     cout << "0" << endl;    cout << "}; ";    cout << argv[1] << "_size = " << count << ";";    cout << endl << endl;     return 0;} 

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t