Autor Beitrag
foxx.gw
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mo 20.06.11 08:39 
Hallo :)
Ich benötige eine C# Konsolenanwendung die Dualzahlen in Dezimalzahlen und Dezimalzahlen in Dualzahlen umrechnet. Leider habe ich nicht viele Kenntnisse in C#, deswegen wende ich mich an euch :) Wär jemand so nett und würde einen Quellcode als Beispiel für meine zwei benötigten Umrechnungen posten?
Und ich habe noch eine Frage: In meiner Konsolenanwendung soll am Anfang abgefragt werden welche Umrechnung (Dual/Dez oder Dez/Dual) gemacht werden soll, dazu soll dann eine "1" bzw. eine "2" eingegeben werden. Jedoch habe ich keine Ahnung wie ich das machen soll, wie gesagt meine C# Kenntnisse tendieren gegen 0 :P
dark-destination1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178
Erhaltene Danke: 21



BeitragVerfasst: Mo 20.06.11 10:27 
dual ->dezimal

doubleZahl= (double) dualZahl

wie es anders herum geht kann ich dir leider nicht sagen
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 20.06.11 10:45 
Hallo und :welcome:

Wenn du bei Google nach Suche bei Google C# ZAHLENSYSTEM suchst, findest du genügend Ergebnisse:
dotnet-snippets.de/d...rechnen-SID1084.aspx
dotnet-snippets.de/d...rechnen-SID1085.aspx

Was die zweite Frage angeht:
Eine Frage pro Thread. :zwinker:
Dr. Hallo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110
Erhaltene Danke: 13

XP
C/C++/C#
BeitragVerfasst: Mo 20.06.11 14:29 
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
//ganze zahlen in dualzahl..
string s="";
int n=123456789,z=(sizeof(int)*8-1);
for (int i=z;i>=0;s+=((n>>i--)&1)==1?"1":"0");
//Konsolenausgabe dualzahl..
Console.WriteLine(s);            
n = 0;
for (int i=0;i<=z;n+=(int)((s[i]-48)*Math.Pow(2,z-i++)));
//Konsolenausgabe ganze zahl..
Console.WriteLine(n);


negative und gleitkommazahlen (double + co) erfordern noch zusatzinfos für eben das vorzeichen
exponent und mantisse. das ist aber definitionssache (auch abhängig vom OS) wie man das dann als dualzahl darstellt.

:oops:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 20.06.11 14:33 
Der Code ist ja... ach du Schreck... kürzer und unübersichtlicher ging wohl nicht? :shock:

Aber ich hatte ja schon zwei Links mit ordentlich formatiertem und geschriebenen Code gepostet. ;-)
Dr. Hallo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110
Erhaltene Danke: 13

XP
C/C++/C#
BeitragVerfasst: Mo 20.06.11 14:50 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Der Code ist ja... ach du Schreck...


..ja stimmt ;-)