Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


please help .....

miss amiss a Member Posts: 4
[b][red]This message was edited by miss a at 2002-9-13 4:55:46[/red][/b][hr]
hi all am abegener in VB C++ and i have a problem in solving this program if any one can help me do please.. as soon as possible
this is the problem

It is required to write a C++ program which converts a decimal signed number to its binary equivalent using two’s complement representation of a negative number. Then your program will print the decimal number and its binary equivalent to the screen. After that your program will convert the binary number to its equivalent decimal number using the polynomial representation of the number and print the output to the screen as a decimal number (Read Chapters 2, 3, and from your text book). Your program must be fully documented with your Name, student’s ID, Section number, Course Name, and the Date of submission on the top of the program.
To convert a negative decimal number to its 2's complement, the following algorithm is used.

2’s Complement Algorithm
Convert each bit to its complement
Add 1 to the least significant bit

Remark: Don’t forget that you are performing addition in binary and the carry will be added to the second higher digit until the sign bit.

Output Sample:
Input an integer number 10
Its binary equivalent 0 0 0 0 1 0 1 0
Its Decimal equivalent after calculating its value using polynomial 10
Do you want more activities: y/n ? y
Input an integer number -8
Its binary equivalent in 2’s complement format 1 1 1 1 1 0 0 0
Its Decimal equivalent after calculating its value using polynomial -8
Do you want more activities: y/n ? n

Programming Assignment: Your program must do the following.
1. Limit your integer number to an 8-bit maximum size with the sign bit. Check the size of each integer. If it is accepted (within the 8-bit register size: 127 for positive and -128 for negative), then go to the next step or inform the user that the number is larger than the size of the machine and ask him to input new number.

2. Convert a positive integer number into binary form using the function: DecimaltoBinary (See the algorithm in your Text book). If the number is negative, then save the sign of the number and convert it to positive so that the function DecimaltoBinary can be used; after the conversion to binary, convert the result to its 2's complement form as shown above using the function: TwosComplement.

4. Print the result of conversion for the decimal number (Use function PrintArray).

5. Check the sign bit of the binary number. If the sign bit is negative, save the sign bit and convert the binary number to positive by taking the 2's complement of the number using the function TwosComplement. Finally, convert the binary number to decimal using the function: BinarytoDeceimal. Print the result of conversion.

6. Ask the user if he/she wants more activity: answer yes/no (your program will be in a loop and it will be terminated only if you say: no).


  • Shawn CarterShawn Carter Member Posts: 0

    _____ ( ) free video tutorials and ebooks about ( Perl, PHP, Python, Visual Basic .NET, C++, Assembly, R, PL/SQL, Objective-C, Java, MATLAB, C, C#, Scratch, Visual Basic, Ruby, JavaScript, Go, Delphi, Swift Lua, VBScript, SAS, Alice, Apex, Fortran, Rust, Kotlin, LabVIEW, Dart, Scala, Bash, Ada, Awk, Scheme, ABAP, Erlang, Lisp, Prolog, F#, COBOL, Transact-SQL, Clojure, FoxPro, Julia, Crystal, Logo, ML, Hack, D ) ________

Sign In or Register to comment.