# ECCP practical assignment 5-1:

Write a program which will ask the user for a number between -128 and 127. The program will then convert the number to binary and display the result. The program will also calculate the number's one's complement and its two's complement and display them.

The output screen should look like this after the program has run:

```Enter a number between -128 and +127: 26
The number 26 in decimal equals 0001 1010 binary
Its one's complement is 1110 0101
Its two's complement is 1110 0110
```
##### Hints:
• Use a char data type for the number being converted.
• Note that the most significant digit of a positive number is zero, and that of a negative is one.

So

```if ( number < 0 )
printf( "1" );
else
printf( "0" );
```
• Shift left and do it again seven more times.

# ECCP practical assignment 5-2:

Write a program that converts a binary number to decimal.

The program prompts the user to enter eight ones or zeros and the program calculates and prints the decimal equivalent.

```Type in an eight bit binary number: 01010101
01010101 = 85 decimal
```