Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<iomanip>
- using namespace std;
- void genAscii();
- string i2b(int i);
- string i2hex(int i);
- int strlen2(string str);
- int c2i(char c);
- int main()
- {
- cout << c2i('1') << endl;
- //genAscii();
- //cout << i2b('A') << endl;
- //cout << i2hex('A') << endl;
- //cout << strlen2("stringisstring");
- return 0;
- }
- void genAscii()
- {
- for (int i = 31; i < 256; i++) //31 is for layout purpose
- {
- cout << setw(3) << i << "-" << char(i) << " ";
- if (i % 10 == 0)
- {
- cout << endl;
- }
- }
- }
- string i2b(int i)
- {
- string binary = "";
- int d = 0;
- while (i > 0)
- {
- d = i % 2;
- binary = char(d + 48) + binary; //int to number must add 48
- i = i / 2;
- }
- return binary;
- }
- string i2hex(int i)
- {
- string hex = "";
- int d = -1;
- while (i > 0)
- {
- d = i % 16;
- i = i / 16;
- if (d>=0 && d<=9)
- {
- hex = char(d + 48) + hex;
- }
- else if (d>=10 && d <= 15)
- {
- hex = char(d + 55) + hex;
- }
- }
- return hex;
- }
- string funAnd(int a, int b)
- {
- string answer = "";
- string strA = i2b(a);
- string strB = i2b(b);
- return answer;
- }
- int strlen2(string str)
- {
- int count = 0;
- while (str[count] != '\0') {
- count++;
- }
- return count;
- }
- int c2i(char c)
- {
- if (c < 48 || c > 57) {
- return -1;
- }
- return c - 48;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement