Commits

Martin Velez committed 677f8af

initial commit

  • Participants

Comments (0)

Files changed (2)

+.PHONY: all clean
+
+PROG=int2bin
+CPPFLAGS+=-Wall
+all: ${PROG}
+
+${PROG}: ${PROG}.cpp
+	g++ ${CPPFLAGS} ${PROG}.cpp -o ${PROG}
+
+clean: 
+	-rm -f *.o ${PROG} core
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+
+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;
+	}
+
+	uintfile.close();
+	
+	return 0;
+}