Created
December 5, 2017 22:37
-
-
Save NorbertFenk/3ca80faa92fd47c7935de6a3ab4d7073 to your computer and use it in GitHub Desktop.
Simple funtion which can generate valid ip4 address from a simple int.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QDebug> | |
QString generateIpFromInteger(quint32 ip) | |
{ | |
QString ipString; | |
for (int i = 0; i < 4; ++i) { | |
ipString.insert(0, QString::number(ip & 0xff)); | |
if (i < 3) { | |
ipString.insert(0, '.'); | |
} | |
ip >>= 8; | |
} | |
return ipString; | |
} | |
int main() | |
{ | |
for(int i = 0; i < 1000; ++i) { | |
qDebug() << generateIpFromInteger(i); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment