Commits

Martin Velez committed 400b842

learned how to enumerate over language of all byte character strings"

Comments (0)

Files changed (1)

+/**
+ * Alphabet = A = {\x00, \x01,...,\xFE,\xFF}
+ * Language = L = A* 
+ * = {\x00, \x01,...,\xFE,\xFF, \x00\x00, \x00\x01,...,\xFF\xFE,\xFF,\xFF,...}
+ * 
+ * This program enumerates over L.
+ * It also helps demonstrate the little-endianess of the x86 system.
+ * 
+ * Partial Output:
+ * 0,0x1,0x2,0x3,...0xfd,0xfe,0xff,0,0x1,0x2,0x3,...0xfffd,0xfffe,0xffff,0,0x1,0x2,0x3,...0xfffffd,0xfffffe,0xffffff,0,0x1,0x2,0x3,
+ *
+*/
+
+
 #include <iostream>
 #include <fstream>
 #include <iomanip>
+#include <math.h>
+#include <limits>
 
 using namespace std;
 
 
 int main()
 {
-	// x86 is little-endian
-	//integer binary reprentation
-
-	int byte_length = 1;
-	int max = numeric_limits<int>::max();	
 	int int_max = sizeof(int);
 
-	ofstream uintfile("uint.bin", ios::binary);
-
-	//iterate over byte length
-	for(int i = 0; i <= int_max; i++) {
-		uintfile.write(reinterpret_cast<const char *>(&i), byte_length);
-		const char* bytes = new char[i];
-		bytes = reinterpret_cast<const char*>(&j);	
-		cout << dec << reinterpret_cast<int>(bytes) << '\t' << hex << showbase << reinterpret_cast<int>(bytes) << endl;
+	ofstream intfile("int.bin", ios::binary);
+ 
+	//first print strings of length 1, then length 2, and so on
+	for(int j = 1; j <= int_max; j++) {
+		for(int i = 0; i < pow(2,8 * j); i++) {
+			if(i == 0 || i == 1 || i == 2 || i == 3 || i == (pow(2,8 * j)-1) || i == (pow(2,8 * j)-2) ) {
+				cout << hex << showbase << i << "," << flush;
+			} 
+			else if(i == (pow(2,8 * j)-3) ) {
+				cout << "..." << flush;
+				cout << hex << showbase << i << "," << flush;
+			}
+			intfile.write(reinterpret_cast<const char *>(&i), j);
+		}
 	}
-
-	uintfile.close();
+	
+	intfile.close();
 	
 	return 0;
 }