الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

هل فيه إختصار لهذا Code

مغلق
بدأه المبرمج القادم في 13 نوفمبر 2002 · 11 رد · 856 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أحد يستطيع أن يساعدني في إختصار هذا البرنامج وأضنه مفهوم ولكنه طويل جداً وفكرته هي أدخل رقم من 1 إلى 15 ويعطيك رمزها بل Binary, decimal, hexdecimal ,octal و التحويل من system to an other system

أنا حاولة في فكرة معادلة لتحويل Number to Binary code بس ماحصلت لكل الأرقام يعني ولو أدخل 21455 يعطيك code تبعة في Number System وش رايكم

#include

int main()

{

int n,k,c,d,o,s;

cout<<" ttt The Name of Allahn";

cout<<"ttt***********************************n";

cout<<"ttt** Welcome to Computer program **n";

cout<<"ttt***********************************n";

cout<<" This program you can know Numbers System codes n";

cout<<"and convert Number(Code)from system to an other.n";

cout<<"t/////////////////////////////////////////////////////////////n";

cout<<"t// 1- Hexdecimal to Binary. 2-Binary to Hexdecimal.//n";

cout<<"t// 3- Decimal to Octal. 4-Octal to Decimal. //n";

cout<<"t// 5- Decimal to all Systems //n";

cout<<"t/////////////////////////////////////////////////////////////n";

cout<<"Please select any one from this to convert from system to an other.n";

cin>>n;

if ( n==1)

{

cout<<" please enter your number in Hexdecimal.from (0 to 15)n";

cin>>k;

if(k==0)

cout<<"tt (0)Hexdecimal=(0000)Binn";

else if(k==1)

cout<<"tt (1)Hexdecimal=(0001)Binn";

else if(k==2)

cout<<"tt(2)Hexdecimal=(0010)Binn";

else if(k==3)

cout<<"tt(3)Hexdecimal=(0011)Binn";

else if(k==4)

cout<<"tt(4)Hexdecimal=(0100)Binn";

else if(k==5)

cout<<"tt(5)Hexdecimal=(0101)Binn";

else if(k==6)

cout<<"tt(6)Hexdecimal=(0110)Binn";

else if(k==7)

cout<<"tt(7)Hexdecimal=(0111)Binn";

else if(k==8)

cout<<"tt(8)Hexdecimal=(1000)Binn";

else if(k==9)

cout<<"tt(9)Hexdecimal=(1001)Binn";

else if(k==10)

cout<<"tt(10,A)Hexdecimal=(1010)Binn";

else if(k==11)

cout<<"tt(11,B)Hexdecimal=(1011)Binn";

else if(k==12)

cout<<"tt(12,C)Hexdecimal=(1100)Binn";

else if(k==13)

cout<<"tt(13,D)Hexdecimal=(1101)Binn";

else if(k==14)

cout<<"tt(14,E)Hexdecimal=(1110)Binn";

else if(k==15)

cout<<"tt(15,F)Hexdecimal=(1111)Binn";

else if(k>=16)

cout<<" The Number is not found!........n";

}

else if(n==2)

{

cout<<"please enter any code in Binary.only(4)character n ";

cin>>c;

if(c==0000)

cout<<"tt(0000)Bin = (0)Hex n";

else if(c==0001)

cout<<"tt(0001)Bin = (1)Hex n";

else if(c==0010)

cout<<"tt(0010)Bin = (2)Hex n";

else if(c==0011)

cout<<"tt(0011)Bin = (3)Hex n";

else if(c==0100)

cout<<"tt(0100)Bin = (4)Hex n";

else if(c==0101)

cout<<"tt(0101)Bin = (5)Hex n";

else if(c==0110)

cout<<"tt(0110)Bin = (6)Hex n";

else if(c==0111)

cout<<"tt(0111)Bin = (7)Hex n";

else if(c==1000)

cout<<"tt(1000)Bin = (8)Hex n";

else if(c==1001)

cout<<"tt(1001)Bin = (9)Hex n";

else if(c==1010)

cout<<"tt(1010)Bin = (10)Hex n";

else if(c==1011)

cout<<"tt(1011)Bin = (11)Hex n";

else if(c==1100)

cout<<"tt(1100)Bin = (12)Hex n";

else if(c==1101)

cout<<"tt(1101)Bin = (13)Hex n";

else if(c==1110)

cout<<"tt(1110)Bin = (14)Hex n";

else if(c==1111)

cout<<"tt(1111)Bin = (15)Hex n";

}

else if(n==3)

{

cout<<" please enter the number in Decimal. from(0 to 7)n";

cin>>d;

if(d==0)

cout<<"tt(0)Decimal=(000)Octal n";

else if(d==1)

cout<<"tt(1)Decimal=(001)Octal n";

else if(d==2)

cout<<"tt(2)Decimal=(010)Octal n";

else if(d==3)

cout<<"tt(3)Decimal=(011)Octal n";

else if(d==4)

cout<<"tt(4)Decimal=(100)Octal n";

else if(d==5)

cout<<"tt(5)Decimal=(101)Octal n";

else if(d==6)

cout<<"tt(6)Decimal=(110)Octal n";

else if(d==7)

cout<<"tt(7)Decimal=(111)Octal n";

else if(d>=8)

cout<<" The Number is not found!........n";

}

else if(n==4)

{

cout<<" please enter the code in octal. only(3)character n";

cin>>o;

if(o==000)

cout<<"tt(000)Octal=(0)Decimal n";

else if(o==001)

cout<<"tt(001)Octal=(1)Decimal n";

else if(o==010)

cout<<"tt(010)Octal=(2)Decimal n";

else if(o==011)

cout<<"tt(011)Octal=(3)Decimal n";

else if(o==100)

cout<<"tt(100)Octal=(4)Decimal n";

else if(o==101)

cout<<"tt(101)Octal=(5)Decimal n";

else if(o==110)

cout<<"tt(110)Octal=(6)Decimal n";

else if(o==111)

cout<<"tt(111)Octal=(7)Decimal n";

}

else if(n==5)

{

cout<<"please enter any number in Decimal . from(0 to 15)n";

cin>>s;

if(s==0)

cout<<"tt(0)Decimal = (0000)Binary.ntt(0)Hexdecimal= (000) Octal. n";

else if(s==1)

cout<<"tt(1)Decimal = (0001)Binary.n tt(1)Hexdecimal= (001) Octal. n";

else if(s==2)

cout<<"tt(2)Decimal = (0010)Binary.n tt(2)Hexdecimal= (010) Octal.n";

else if(s==3)

cout<<"tt(3)Decimal = (0011)Binary.n tt(3)Hexdecimal= (011) Octal. n";

else if(s==4)

cout<<"tt(4)Decimal = (0100)Binary.ntt(4)Hexdecimal= (100) Octal. n";

else if(s==5)

cout<<"tt(5)Decimal = (0101)Binary.ntt(5)Hexdecimal= (101) Octal. n";

else if(s==6)

cout<<"tt(6)Decimal = (0110)Binary.ntt(6)Hexdecimal= (110) Octal. n";

else if(s==7)

cout<<"tt(7)Decimal = (0111)Binary.ntt(7)Hexdecimal= (111) Octal. n";

else if(s==8)

cout<<"tt(8)Decimal = (1000)Binary.ntt(8)Hexdecimal= (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==9)

cout<<"tt(9)Decimal = (1001)Binary.ntt(Q)Hexdecimal= (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==10)

cout<<"tt(10)Decimal = (1010)Binary.ntt(A)Hexdecimal = (Q) Octal.nnnQ manes system has not code in this number.n";

else if(s==11)

cout<<"tt(11)Decimal = (1011)Binary.ntt(B)Hexdecimal = (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==12)

cout<<"tt(12)Decimal = (1100)Binary.ntt©Hexdecimal = (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==13)

cout<<"tt(13)Decimal = (1101)Binary.ntt(D)Hexdecimal= (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==14)

cout<<"tt(14)Decimal = (1110)Binary.ntt(E)Hexdecimal= (Q) Octal. nnnQ manes system has not code in this number.n";

else if(s==15)

cout<<"tt(15)Decimal = (1111)Binary.ntt(F)Hexdecimal = (Q) Octal. nnnQ manes system has not code in this number.n";

}

else if(n>=6)

{

cout:(

//عذرا , قمت بتعديل بسيط ليظهر الكود بصورة افضل .

#2

السلام عليكم ,,,,

أخي المبرمج القادم:

أولاً انا اخذت نظرة عامة على البرنامج و لي ملاحظات التالي:

إجعل التحويل برمجياً ...و إستخدم الدوال Functions

مع تحياتي ,,, طلال.

#3

البرنامج طويل لانكم لم تستخدموا علميات الحسابية في التحويل من النظام الى اخر

وفي حال الهيكسن والاوكتن يجب ان التستخدم char not int

وشكرا

اختكم

لغة سي

#4

استخدم مبدأ الازاحة أو باقي القسمة على 2 بالنسبة للثنائي .. وباقي القسمة على 8 بالنسبة للثماني وهكذا .. بالنسبة لقرائة الرقم من الكونسول فاقرأها كلها كسلاسل ومن ثم:

1 - إذا كنت تقرأ بايناري فقم بنجويل كل خانة محرفية 1 أم 0 ووضع البت في المحل المناسب في متحول ما.

2 - إذا كنت تقرأ هكسا فقم بمعالجة كل 4 بتات على حدى بشروط بسيطة

3 - إذا كنت تقرأ رقم ثماني فقم بتحويله إلى عشري حتى تقدر أن تحفظه بمتحول ...

Coding on the Cloud and for the Cloud!

My Blog

#5

السلام عليكم ورحمة الله وبركاته .

شكراً لكم جميعاً على هذه المساعدة وأنا أتأسف جداً على التأخر في الرد وذلك لأني ذهبت إلى أحد المناطق وما كان فيها كهربة ولاتلفون ولا نت وإلا الجوال يشتغل بعد طلبة يعني ( مايشتغل إلا بالعافية ) . فشكراً لكم جميعاً.(f)

ولكن الأستاذ هاني فكرة الرد كانت ممتازة جداً ومختصرة ولكن بما إني مبتدء جداً في البرمجة لذالك قد لا احسن التطبيق والتركيب الصحيح للبرنامج ودي تعطيني أو أي شخص من الأساتذة مفتاح البرنامج وبداية العمل وأنا أعدكم بتكملته :D وإخراجه بصورة جيدة إن شاء الله تعالى .

وشكرا لجميع الأساتذة الكرام (f)

تلميذكم المبتدء المبرمج القادم:o

#6

مثل

اذا كان لديك رقم 5= 101

بالعمليات الحسابية

5/2=2 والباقي 1

5%2=1

2/2=1 والباقي 0

2%2=0

1/2=0 والباقي 1

1%2=1

ويكون الرقم 101

اختكم

لغة سي

#7

شكراً للأخت لغة cولكن أنا بجرب وإن شاء الله اكتب ماتوصلة له .

(gift)

ملاحظة

وإن كان هناك زيادة توضيح أرجو أن لا تبخلوا عليه بها فأنا في أمس الحاجة لها .

شكراً لكم جميعاً

أخوكم المبتدء

المبرمج القادم :o

#8

من أجل التحويل بين الأنظمة العددية أنصحك باستخدام

itoa - ltoa -

char* str;

int i;

cout << "Enter decimal number : ";

cin >> i;

itoa(i,str,2)

إذا أدخلت 7 :

str = 111;

جرب ولن تندم

#9

طبعا هذا أفضل شئ أخي اسماعيل :) ولكن فقط في حالة لم نسأل عن المضمون .. :)

الدالة التي ذكرتها تصلح للتحويل بين وإلى أي من الأنظمة العددية ..

Coding on the Cloud and for the Cloud!

My Blog

#10

(f) شكرا لجميع الأخوة .

ولكن الاخ اسماعيل ما عمل هذه الدالة itoa وكيف تكتب في البرنامج ...... :confused:

حقيقة جديدة عليه:o

#11

البرنامج التالي يحول من الترقيم الثنائي إلى العشري

#include

#include

void main()

{

long temp, d, b, j;

cin >> b;

temp = 0;

d = 0;

j = 0;

while( b != 0 )

{

temp = fmod( b, 10.0 );

if( temp == 1 )

d = d + pow( 2, j );

j++;

b = b / 10;

}

cout << d;

}

#12

السلام عليكم .

حقيقة إن الكود يأخ إسماعيل إلي سويته خجعبه //شدة الذهول.

وأنا أدعوا لك بعد الإفطار بالتوفيق والسداد .

حقيقة إني متفاجئ لأني دخلت أرقام وطلع الجواب صح وااااااااااو .

مشاء الله عليك . بعدين تقلي سم عليه سم عليه لا تعيني فأنا تراني سميت .

ولكن المهم الشباب يسمون عليك .

شكرا لك ولجميع المهندسين والمبرمجين على تفاعلهم الجميل المثمر. (gift) (f)

أخوكم المبتدء المبرمج القادم :o

هذا الموضوع مغلق.

مواضيع مشابهة