I can't understand why franco wants to apply endianess to arrays?
What would be shown on the screen dependently on edianess?Qt Code:
#include <iostream> int main() { unsigned int a = 0x12345678; char b[4] = { 0x12, 0x34, 0x56, 0x78 }; unsigned int *c = (unsigned int *)b; std::cout << " a = " << std::hex << a << std::endl; std::cout << "*c = " << std::hex << *c << std::endl; return 0; }To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Very well 3 of you!!!!
Well, I would convert some bytes of a QByteArray into a QString containing value that must be converted from a hex representation so:
Qt Code:
To copy to clipboard, switch view to plain text mode
Is there a way to do it of I have to manually convert it?
Regards
Franco Amato
It looks to me like the sender has chosen to encode a time of day as two independent bytes. The first byte is the hour (presumably 0 to 23) and the second byte is the minute (0 to 59). You can get what you want by using each byte independently: in your case the first byte is 8, the second is 15 (or 0x0F). I would suggest using a QString format and the QString::arg() method twice.
Yes it's so.
Thank you. I'll try your suggestionThe first byte is the hour (presumably 0 to 23) and the second byte is the minute (0 to 59). You can get what you want by using each byte independently: in your case the first byte is 8, the second is 15 (or 0x0F). I would suggest using a QString format and the QString::arg() method twice.
Franco Amato
Your code does not make any sense for me. I think that opening 2 tabs in Assistant (QByteArray, QTime) and just using brain for 5 to 10mins (10 is too much but I can understand it) can give you a solution. Why are you asking us for almost any smallest issue which is even not connected with any Qt specific features, those issues just requires you to think for a while about the problem or sometimes to also read about some basics like endianess, where google is your friend and can give you answer in 1s - so you can get the answer for some question faster than even writing this question on forum (any forum, not only Qt Centre).
I really want to help people here on Qt Centre, but for example: when I am helping my younger brother to do his first C++ projects for his studies, I don't give you straight solution, I just want him to think for a while as I'm giving only hints so finally he discovers right solution by himself with a little help, so when he faces similar solution to days later then he knows those basic steps leading him to the right solution. He knows he can use www.cppreference.com or google for some specific, detailed explanations.
But you look like don't know that google and Qt Assistant exist. You look like you rather want to spend 5minutes on writing new post and waiting minutes to hours for answer than just spending those 5 minutes on finding the solution...
Why can't you learn that you need to know some basic stuff to understand some more complex, as usually this complex stuff is explained with those basics?
Why can't you learn that "alignment" and "ordering" is not the same especially when you talk about endianess?
You just want to jump over the problems to get the working code fast. If you want so, then maybe you should ask someone to do the job for you and pay him for his job?
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Dear faldżip,
I don't need another father as I already have Wysota that likes doing sermons.
Convert content bytes of a QString from exadecimal to other format is a Qt related stuff or not?
I already got the answer from ChrisW67 that suggested to convert byte to byte and that's not possible to convert all the content, so please don't loose your time to write sermons as wysota always does.
If you don't want reply to my question or if you think you are a superman thinking that other persons don't use their brain, please simply don't reply so you can have more time to help your younger brother.
I know assistant and google, and if I ask something here if because I can not solve it.
Another thing: I don't need to convert a value to a time, I simply need to convert a hex value to a decimal value, so maybe you didn't well read my question, seems that I'm not the only that must turn on his brain
Meanwhile thank you for the time you spent and alignment and ordering for my poor english vocabulary is the same, the important is the concept not the world or you also would criticize my english skill?
Last edited by franco.amato; 27th April 2010 at 18:33.
Franco Amato
faldżip I wrote this code to achieve my goal:
now oraInizio contains 0815 that's exactly what I wanted. I'm sure is not the fastest way but I'm not a superman as you.
Do you see the needed of the QTime here?
Franco Amato
I would suggest that you avoid being so personal. Remember we are all helping you out of good will and if you act in an annoying way you risk that we turn our attention elsewhere where our help is more appreciated.
As for your English skills remember it is you who has to formulate the problem clearly and it is only your responsibility if anybody else misunderstands what you say. "Alignment" and "order" have very different meanings when it comes to processors (and you as a 'hardware designer' should be aware of that) and I'm sure any decent dictionary would agree with me. So don't blame others for trying to help you and start thinking whether you could have done more yourself.
If you don't want my technical advice, you won't receive it but I'm still a moderator on this forum and I kindly ask you to behave yourself and appreciate that others devote their time to trying to help you. It is a very rare case that I remind someone I have means of enforcing order here so treat it as a serious warning. I will probably not use my power because I think I may not be objective in this caase but I might ask other moderators to take a closer look at this thread.
Wysota your're right,
but sincerely I'm a bit tired to listen things as "use your brain", I very appreciate your help but you also should understand people that doesn't have your [Qt, c++] knoledge level.
Every time I don't understand something or everytime something doesn't work I before search on internet, or in the forum, online books and so on, and only when I can not solve it I ask here.
Now forget the reference to "wysota" in my last post (only was a joke), but faldżip should not think that people are foo and that don't use their brain at work.
Please appreciate my apology.
Regards
Franco Amato
Franco,
when I started helping people solve their Qt problems, my Qt knowledge was exactly zero and my C++ skills were not much better. All my experience comes from dealing with problems I knew nothing about and "using my brain" and curiosity (or urge) to gain more knowledge. If I waited for others to present me with ready solutions, I wouldn't have learned anything. If you want to improve, you have to gain 95% of the knowledge on your own and only the remaining five by asking others. Take a step back and see for yourself - your problem has nothing to do with Qt or even with C++. The fact that C++ and Qt are your tools is completely meaningless because in my point of view your main issue is that it is hard for you to find solutions to problems on your own - without Internet, books or other people.
Your appology is not required (though appreciated) as I don't feel offended. I just don't want to risk you discouraging people who are willing to share their own knowledge and experience, like Filip (faldżip).
There is more than one way to do these things. Some more complicated than others, and some with slightly different results. For example, your code converts two bytes to hex, pulls the hex string apart, and converts the hex strings back to decimal. Far more direct approaches exist:
This also gives a leading 0 on the hours and minutes (I am not sure your solution does).Qt Code:
To copy to clipboard, switch view to plain text mode
You could use QTime to achieve this goal. Something like:
Using QTime has the advantage that it can do validation ( QTime::isValid() ), interval mathematics (QTime::secsTo()), or ouput several different formats (QTime::toString()).Qt Code:
// and to make your string from it...To copy to clipboard, switch view to plain text mode
(Both code examples untested... not at my Qt machine)
Last edited by ChrisW67; 27th April 2010 at 22:46. Reason: updated contents
No, it's not. This is basic, fundamental, first-semester computer science.
You're asking very basic questions in a very specialized forum. You should go elsewhere and master the basics. The knowledge of those contributing to this forum is wasted until you comprehend the fundamentals.
The thing is that any hexadecimal numbers are not needed at all here and your problem is (was?) to convert 2 bytes containing hours and minutes to some string.
That is why suggested using QTime (it can be useful in case of further processing of this time you get). If you would bother to read Qt Docs next time, you would know this before Chris gave the exact solution which you can simply copy and paste - I'm almost sure that you still don't know what those two '0' in QTime constructor's call means. And you probably won't read the docs to get know that you don't have to write them there.You could use QTime to achieve this goal. Something like:
Using QTime has the advantage that it can do validation ( QTime::isValid() ), interval mathematics (QTime::secsTo()), or ouput several different formats (QTime::toString()).Qt Code:
// and to make your string from it...To copy to clipboard, switch view to plain text mode
Last edited by faldzip; 28th April 2010 at 09:15. Reason: OK, Following Wysota's next post I cut out this part
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Filip, let's drop the "Luke, I am your father" part of the discussion please.
Seconds and mseconds.I'm almost sure that you still don't know what those two '0' in QTime constructor's call means.
Because there is a default value set.And you probably won't read the docs to get know that you don't have to write them there.
Don't be so sure please!
Franco Amato
Bookmarks