View difference between Paste ID: mD0yPyGm and Ld8JR6uv
SHOW: | | - or go back to the newest paste.
1
    using System;
2
    using System.Collections.Generic;
3
    using System.Linq;
4
    using System.Text;
5
    using System.Threading.Tasks;
6
7
    namespace ConsoleStrings
8
    {
9
        class Stringklasse
10
        {
11
            private string str1;
12
13
            public Stringklasse(string str1)
14
            {
15
                this.str1 = str1;
16
            }
17
18
            public bool IsPalindroom()
19
            {
20
                bool palindroom = true;
21
                for (int i = 1; i < str1.Length / 2; i++)
22
                {
23
                    if (str1[i] != str1[str1.Length - i])
24
                        palindroom = false;
25
                }
26
                return palindroom;
27
            }
28
29
            public bool IsBinair()
30
            {
31
                bool binair = true;
32
                for (int i = 1; i < str1.Length; i++)
33
                {
34
                    if (str1[i] != '1' && str1[i] != '0')
35
                        binair = false;
36
                }
37
                return binair;
38
            }
39
40
            public bool BinToDec()
41
            {
42
                int decimaal=0;
43
                int gewicht = 1;
44
                if (IsBinair() == false)
45
                    return false;
46
                for (int i = str1.Length-1; i >=0; i--)
47
                {
48
                    decimaal += ((str1[i])-48) * gewicht;
49
                    gewicht *= 2;
50
                }
51
                Console.WriteLine(decimaal);
52
                return true;
53
            }
54
55
            public bool IsHexadec()
56
            {
57
                bool hexadec = true;
58
                str1=str1.ToUpper();
59
                for (int i=1;i<str1.Length;i++)
60
                {
61
                    char c = str1[i];
62-
                    (c >= 'a' && c <= 'f') ||
62+
63
                    (c >= 'A' && c <= 'F'));
64
                    if(!hexadec)
65
                     return false;
66
                }
67
                return hexadec;
68
                //return System.Text.RegularExpressions.Regex.IsMatch(str1, @"\A\b[0-9a-fA-F]+\b\Z");
69
            }
70
71
            public bool HexaToDec()
72
            {
73
                int decimaal = 0;
74
                int gewicht = 1;
75
                int waarde = 0;
76
                if (!IsHexadec())
77
                    return false;
78
                for  ( int i = str1.Length - 1;i>=0;i--)
79
                {
80
                    if (str1[i] >= '0' && str1[i] <= '9')
81
                        waarde = str1[i] - 48;
82
                    else if (str1[i] >= 'A' && str1[i] <= 'F')
83
                        waarde = str1[i] - 55;
84
                    decimaal = waarde * gewicht;
85
                    gewicht *= 16;
86
                }
87
                Console.WriteLine(decimaal);
88
                return true;
89
            }
90
        }
91
    }