Trouble converting a decimal to a hexadecimal in its string form

Pages: 12

This thread should have stopped at «I will use it if I can't manage to finish my own in time.»


Yes, especially when I asked a question to help me understand inheritance and polymorphism better with code that would actually work, "Solve my homework for me, and do it in a manner I approve of, and I guess if that's the best you can do I'll use it" manages to get actual solutions.
closed account (48T7M4Gy)
;)
gentleguy wrote:
@Half Life G Man
How long did you spend writing "these"? :O


4 hours
Who the hell reported kemort & Half Life G Man's posts I don't get it...
closed account (E0p9LyTq)
Thank you so much for your code. I will use it as a last resort if I somehow can't manage to finish my own in time. That means that I still have time left and I am awaiting some helpful opinions and comments regarding my own code (and its algorithm), and avoid cheating when unnecessary. Your algorithm & code may look standard and more professional, but I think mine is a little bit faster than yours.

If THAT is the case then you are expressly forbidden from using my code, PERIOD.

For someone wanting help you sure have a bad attitude when others offer FREE help.

Continue creating flawed and unworkable code, and spurning help that points to code that actually works.
Last edited on
Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <stdio.h>
#include <string>
#include <array>
#include <windows.h>

using namespace std;
int main()
{
    unsigned int i, j, input, pos, sleep_interval = 10;
    std::array<char, 11> hexa;
    std::string hexa_table = "0123456789ABCDEF";

    bool anim;
    
    cout << "(Decimal to hexadecimal converter)" << endl << endl;

    cout << "Input an integer you want hexalized : ";
    cin >> input;
    do
    {
        cout << "Do you want some additional animation effect (Y/N) : ";
        cout >> hexa[0];
        char* m = strchr("XY", toupper(hexa[0]));
        if(m != nullptr)
        {
            anim = (*m == 'Y'); cout << endl; break;
        }

        cout << endl;
        cout << "Error : Wrong input. Please try again..." << endl << endl;
    }

    i = j = input;
    hexa.fill(char(NULL));
    pos = hexa.size() - 2;

    if(anim == false) // (FurryGuy)'s & (kemort)'s
    do
    {
        hexa[pos--] = hexa_table[input % 16]; // Now I know it is so so simple!!!
    } while ((input /= 16) != 0);

    input = (j = j);
    if(anim == true)
    for(i = 0; i <= input; ++i)
    {
        j = hexa[pos];
        if((hexa[pos] = hexa_table[i % 16]) == hexa_table[0x0] && (j == hexa_table[0xF]))
        {
            do
            {
                hexa[pos] = hexa_table[0x0];
                if(hexa[--pos] == NULL) hexa[pos] = hexa_table[0x0];
            } while((hexa[pos] = strchr(hexa_table, hexa[pos])[0] + 1) > hexa_table[0xF]);

            pos = hexa.size() - 2;
        }

        j = 0; for( ;; )
        if(hexa[j++]) 
        {
            cout << "/t" "0x" << &hexa[j-1] << endl; break;
        }

        Sleep(sleep_interval);
    }

    for (i = 0; i < hexa.size(); ++i)
    if(hexa[i] != NULL)
    {
        hexa[i - 1] = 'x';
        hexa[i - 2] = '0';
        pos = i - 2; 
        break;
    }

    cout << endl;
    cout << "The hexadecimal number is : " << endl;
    cout << "  + My approach : " << &hexa[pos] << endl;
    cout << "  + Expected : 0x" << std::hex << input << std::dec << endl;

    cin.get();
    return 0;
}


1.
(Decimal to hexadecimal converter)

Input an integer you want hexalized : 3820
Do you want some additional animation effect? (Y/N) : N

The hexadecimal number is : 
  + My approach : 0xEEC
  + Expected : 0xeec 


2.
(Decimal to hexadecimal converter)

Input an integer you want hexalized : 20
Do you want some additional animation effect? (Y/N) : Y

    0x1
    0x2
    0x3
    0x4
    0x5
    0x6
    0x7
    0x8
    0x9
    0xA
    0xB
    0xC
    0xD
    0xE
    0xF
    0x10
    0x11
    0x12
    0x13
    0x14

The hexadecimal number is : 
  + My approach : 0x14
  + Expected : 0x14 


Any comments regarding my final code?
Thanks.
Last edited on
@Half Life G Man

It is so fascinating you put so much efforts in correcting my code like that. And this feels very unique. It is like "these things that you tell me" are well beyond informative and they are so detailed. I can feel like I am reading a beautiful and creative essay for real which is no doubt flowing so smoothly from the very beginning to the very end. I never feel "forced" at all, you explained throughly every single little thing and pay close attention to every possible details, so in order to make sure that I could get to realize and recognize every single mistake I have made with ease and with absolutely no difficulty. You also never ever changed your tone throughout your entire explanation, you are impressing me with that cute gentle side of yours and you never ever say a harsh thing to me regarding something that may be considered trivial or even stupid. Thus, you earn my total respect, my reward, my trust and you have throughly captured my heart. To me, you are just too perfect, a wonderful mysterious gentleman indeed. I just want to express my pure gratitude to you as detailed as possible (just as much as how you invested and took your time to give me an explanation as detailed and as valuable as possible). I want to talk to you more, and I will definitely make sure to send you my own hello personal message just in case.

Beyond masterpiece,
11/10
Today is my birthday!!!

Hooray!!! I'm so happy! Hooray!!! I'm so happy!

I am the happiest and the most charming & wondeful person in the world. YEAH!

It feels so good I can die in heaven now...
Anyone wish me a happy birthday? :)
closed account (48T7M4Gy)
.
Last edited on
closed account (3h0oLyTq)
Happy birthday SakurasouBusters!

I hope this special day will bring you lots of happiness, love and fun. You really, really deserve them a lot. Enjoy!

Have a wonderful birthday. I truly wish your everyday to be filled with lots of love, enjoyment, laughter, happiness and the warmth of sunshine.


Happy birthday to you
Happy birthday to you
Happy birthday Happy birthday
Happy birthday to you


Yeah! :D
Topic archived. No new replies allowed.
Pages: 12