Skip to content

Instantly share code, notes, and snippets.

@NorbertFenk
Created December 5, 2017 22:37
Show Gist options
  • Save NorbertFenk/3ca80faa92fd47c7935de6a3ab4d7073 to your computer and use it in GitHub Desktop.
Save NorbertFenk/3ca80faa92fd47c7935de6a3ab4d7073 to your computer and use it in GitHub Desktop.
Simple funtion which can generate valid ip4 address from a simple int.
#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