#include <iostream>
#include <string>
#include "font.h"
using namespace std;
// NOTE: www.cprogramming.com/tutorial/bitwise_operators.html
void display_char(int);
int find_char(unsigned char(*)[5]); // trouble declaring function prototype
int main()
{
// PART 1:
for(int j = 0 ; j < 96; j++)
{
display_char(j);
cout << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << endl;
}
// PART 2:
int char_index = find_char(font_5x7[96][5]);
cout << "The index of our character for the outer dimension of font_5x7[95][5] is " << char_index << endl;
return 0;
}
void display_char(int index) // index = {0 ... 95} for 96 ASCII chars
{
for(int i = 7 ; i > 0; i--) // 7 iter. {7 ... 1}
{
for(int j = 0 ; j < 5; j++) // 5 iter. {0 ... 4} , TOT. ITER: 35
{
// j keeps track of a collumns of bits making up one byte; 5 collums of bytes = 1 bitmap for an ASCII char
unsigned char target = font_5x7[index][j];
// '<<' left shift operator
if((target & (1 << i)) == 0) cout << "At letter index: " << index << ',' << " column: " << j << ", there is a 0" << endl;
else cout << "At letter index: " << index << ',' << " column: " << j << ", there is a 1" << endl;
}
cout << endl;
}
}
// INPUT: two-dimensional unsigned char array font_5x7[95][5] from font.h
// OUTPUT: integer type representing the index of the bitmapped character in font_5x7 else -1
int find_char(unsigned char font_5x7[][5])
{
unsigned char lookfor[5] = {0xfe,0x92,0x92,0x92,0x82};
for(int i = 0; i < 95; ++i)
{
int check = 0;
for(int j = 0; j < 5; ++j)
{
if(lookfor[j] == font_5x7[i][j])
{
++check;
if(check == 5) return i;
continue;
}
else break;
}
}
return -1;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSAiZm9udC5oIgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gTk9URTogd3d3LmNwcm9ncmFtbWluZy5jb20vdHV0b3JpYWwvYml0d2lzZV9vcGVyYXRvcnMuaHRtbAoKdm9pZCBkaXNwbGF5X2NoYXIoaW50KTsKaW50IGZpbmRfY2hhcih1bnNpZ25lZCB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