Ich habe ein Programm geschrieben, das Dezimal in Binärdatum umwandelt. Ich bin sicher, es gibt einen einfacheren Weg, also können Sie es mir zeigen? < /P>
#include
#include
using namespace std;
int a1, a2, remainder;
int tab = 0;
int maxtab = 0;
int table[0];
int main()
{
system("clear");
cout > a1;
a2 = a1; //we need our number for later on so we save it in another variable
while (a1!=0) //dividing by two until we hit 0
{
remainder = a1%2; //getting a remainder - decimal number(1 or 0)
a1 = a1/2; //dividing our number by two
maxtab++; //+1 to max elements of the table
}
maxtab--; //-1 to max elements of the table (when dividing finishes it adds 1 additional elemnt that we don't want and it's equal to 0)
a1 = a2; //we must do calculations one more time so we're gatting back our original number
table[0] = table[maxtab]; //we set the number of elements in our table to maxtab (we don't get 10's of 0's)
while (a1!=0) //same calculations 2nd time but adding every 1 or 0 (remainder) to separate element in table
{
remainder = a1%2; //getting a remainder
a1 = a1/2; //dividing by 2
table[tab] = remainder; //adding 0 or 1 to an element
tab++; //tab (element count) increases by 1 so next remainder is saved in another element
}
tab--; //same as with maxtab--
cout =0) //until we get to the 0 (1st) element of the table
{
cout
Ich habe ein Programm geschrieben, das Dezimal in Binärdatum umwandelt. Ich bin sicher, es gibt einen einfacheren Weg, also können Sie es mir zeigen? < /P> [code]#include #include
using namespace std; int a1, a2, remainder; int tab = 0; int maxtab = 0; int table[0]; int main() { system("clear"); cout > a1; a2 = a1; //we need our number for later on so we save it in another variable
while (a1!=0) //dividing by two until we hit 0 { remainder = a1%2; //getting a remainder - decimal number(1 or 0) a1 = a1/2; //dividing our number by two maxtab++; //+1 to max elements of the table }
maxtab--; //-1 to max elements of the table (when dividing finishes it adds 1 additional elemnt that we don't want and it's equal to 0) a1 = a2; //we must do calculations one more time so we're gatting back our original number table[0] = table[maxtab]; //we set the number of elements in our table to maxtab (we don't get 10's of 0's)
while (a1!=0) //same calculations 2nd time but adding every 1 or 0 (remainder) to separate element in table { remainder = a1%2; //getting a remainder a1 = a1/2; //dividing by 2 table[tab] = remainder; //adding 0 or 1 to an element tab++; //tab (element count) increases by 1 so next remainder is saved in another element }
tab--; //same as with maxtab-- cout =0) //until we get to the 0 (1st) element of the table { cout
Ich besuche gerade einen College-Kurs über Betriebssysteme und wir lernen, wie man von binär in hexadezimal, dezimal in hexadezimal usw. konvertiert. Und heute haben wir gerade gelernt, wie...
Ich versuche, mein Verständnis des STFS -Dateiformats zu verbessern, indem ich ein Programm zum Lesen aller verschiedenen Informationsbits verwenden. Mit einer Website mit einer Referenz, auf die...
Ich erstelle eine Chatbot -App und habe ein Problem mit ListView, wenn ich Message ListView nur an einen bestimmten Punkt sende, sollte aber bis zum Ende sein.
import...