You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, July 28th 2004, 11:59pm

string to hex

how can I change singe character to it's hex number in 2 digital format?
I try a few method but it isn't it, this cen be some links or examples

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Thursday, July 29th 2004, 12:06am

RE: string to hex

Try this:

Source code

1
2
3
4
QString str;
        str = QString( "Decimal 63 is %1 in hexadecimal" )
                .arg( 63, 0, 16 );
        // str == "Decimal 63 is 3f in hexadecimal"


You'll probably have a problem though, when you try to convert something, that is less than 10h, because you'll probably not get the leading 0, but you can simply prepend '0' then.

3

Thursday, July 29th 2004, 1:56pm

but its change only numbers and my program must change letter

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Thursday, July 29th 2004, 2:02pm

A letter is also a number... you can do .arg('A', 0, 16); and it will convert A into an appropriate hex representation.

5

Thursday, July 29th 2004, 2:05pm

but I don't enter letter into code manualy but by QCString with I revice from server, and firs I must convrect it to char?

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

6

Thursday, July 29th 2004, 2:13pm

IF you get a string like this
"54"
You can first convert it to a number usign QString::toInt

Cheers,
_
Qt/KDE Developer
Debian User

7

Thursday, July 29th 2004, 2:21pm

I have string like this: "abc" not some int. If I have some numbers I know how to convrect to int but I don't know how to convrect letter to its hex number

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

8

Thursday, July 29th 2004, 2:26pm

Source code

1
2
3
4
5
6
7
QString str("abc");

for(int i=0; i<str.length();i++){
    char s = str[i];
    QString hexadecimal("%1").arg((int)s, 0, 16);
    // do something with it here
}

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

9

Thursday, July 29th 2004, 4:13pm

QString::toInt

hint: second parameter
another hint: 16

Cheers,
_
Qt/KDE Developer
Debian User

10

Tuesday, March 1st 2005, 10:33pm

Well I was searching in the forum for convert a qstring to hex, but I have a problem compiling.

error: cannot convert `QCharRef' to `char' in initialization

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

12

Wednesday, March 2nd 2005, 10:06am

Well, I do the next code a simple copy paste of your sample

QString str("abc");

for(int i=0; i<str.length();i++){
char s = str;
QString hexadecimal("%1").arg((int)s, 0, 16);
// do something with it here
}