1541110

Post on 11-Apr-2016

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Desc

TRANSCRIPT

Start

Input a Binary Number BN

Does BN have more than 8 characters or start with a 0 or contain numbers that aren’t 0

or 1

Yes

No

CharAt = Value of the character in position(P)

P = 0

N = Number of characters

in BN

Length = Number of

characters in BN

(CharAt*2 ) = Answer

N

N = N - 1

Sum = Sum + Answer

Sum = 0

P = P + 1

Does P = Length No

Yes

Display (BN+“ to Decimal = ’’+Sum)

Does BN have more than 4 characters?

No

Display a new line

Set the last 4 characters as Input2

Set the remaining first characters as

Input1

(CharAt2*2 ) = Answer2

N2 = N2 - 1

Sum2 = Sum2 + Answer2

P2 = P2 + 1

Does P2 = Length2

N2

CharAt2 = Value of the character in position(P)

P2 = 0

N2 = Number of

characters in Input2

Length2 = Number of

characters in Input2

Sum2 = 0

Comment: If (P)=0 then it will be the

first character of BN

No Yes

Does (Sum2 =10)

Yes

Sum2 = (“A”)

Does (Sum2 =11)

Yes

Sum2 = (“B”)

Does (Sum2 =12)

Yes

Sum2 = (“C”)

Does (Sum2 =13)

Yes

Sum2 = (“D”)

Does (Sum2 =14)

Yes

Sum2 = (“E”)

Does (Sum2 =15)

Yes

Sum2 = (“F”)

No

No

No

No

No

No

Display (BN “to Hexadecimal = “+Sum1+Sum2)

(CharAt1*2 ) = Answer1

N1 = N1 - 1

Sum1 = Sum1 + Answer1

P1 = P1 + 1

Does P1 = Length1

N1

CharAt1 = Value of the character in position(P1)

P1 = 0

N1 = Number of

characters in Input1

Length1 = Number of

characters in Input1

Sum1 = 0

No

Yes

Sum1 = (“A”)

Does (Sum1 =11)

Yes

Sum1 = (“B”)

Does (Sum1 =12)

Yes

Sum1 = (“C”)

Does (Sum1 =13)

Yes

Sum1 = (“D”)

Does (Sum1 =14)

Yes

Sum1 = (“E”)

Does (Sum1 =15)

Yes

Sum1 = (“F”)

No

No

No

No

Yes

Does (Sum1 = 10)

No

Display a new line Yes

CharAt = Value of the character in position(P)

P = 0

N = Number of characters

in BN

Length = Number of

characters in BN

(CharAt*2 ) = Answer

N

N = N - 1

Sum = Sum + Answer

Sum = 0

P = P + 1

Does P = Length No

Does (Sum =10)

Yes

Sum = (“A”)

Does (Sum =11)

Yes

Sum = (“B”)

Does (Sum =12)

Yes

Sum = (“C”)

Does (Sum =13)

Yes

Sum = (“D”)

Does (Sum =14)

Yes

Sum = (“E”)

Does (Sum =15)

Yes

Sum = (“F”)

No

No

No

No

No

No

Display (BN “to Hexadecimal =

“+Sum)

Yes

End End

Assumptions

1) Binary is a base two numeral system, which uses only 0's and 1's.

2) Decimal is a base ten system.

3) Hexadecimal is a base sixteen system, it is made up of sixteen characters 0-9 and A,B,C,D,E,F.

Binary to Decimal and Hexadecimal Pseudo Code

Input: UserInput is an integer

Length is an integer that counts the amount of characters in the input

N is an integer that counts the amount of characters in the input

Let Position be an integer that makes CharAt move onto the next character as it increases in value, 0 being the

first value

If UserInput is not made up of 1’s and 0’s or input has more than 8 characters Then

Output: “Please enter a correct binary number that is 8 characters or less”

Else

For (Position = 0, Position < Length, Position = Position +1)

CharAt is the value of the character in the UserInput at a current (Position)

Let N = N – 1

Let Answer = (CharAt * 2(N))

Let Sum = Sum + Answer

End For

Output: (UserInput)+ “Converted to Decimal = “ +(Sum)

End If

If UserInput is not made up of 1’s and 0’s or input has more than 8 characters Then

Output: “Please enter a correct binary number that is 8 characters or less”

Else If input is greater than 4 characters Then

Output on a new line: UserInput “ Converted to Hexadecimal = ”

Let Input2 be the last 4 characters of the UserInput

Let Input1 be the remaining first characters of the UserInput

Let Position1 be an integer that makes CharAt1 move onto the next character as it increases in value, 0

being the first value

Let Position2 be an integer that makes CharAt2 move onto the next character as it increases in value, 0

being the first value

For (Position1 = 0, Position1 < Length1, Position1 = Position1 + 1)

CharAt1 is the value of the character in the UserInput at a current (Position1)

Let N1 = N1 – 1

Let Answer1 = (CharAt1 * 2(N1)

)

Let Sum1 = Sum1 + Answer1

End For

If (Sum1 = 10)

Output on the same line as the last Output: “A”

Else If (Sum1 = 11)

Output on the same line as the last Output: “B”

Else If (Sum1 = 12)

Output on the same line as the last Output: “C”

Else If (Sum1 = 13)

Output on the same line as the last Output: “D”

Else If (Sum1 = 14)

Output on the same line as the last Output: “E”

Else If (Sum1 = 15)

Output on the same line as the last Output: “F”

Else Output on the same line as the last Output: (Sum1)

End If

For (Position2 = 0, Position2 < Length2, Position2 = Position2 + 1)

CharAt2 is the value of the character in the Input2 at a current (Position2)

Let N2 = N2 – 1

Let Answer2 = (I2 * 2(N2)

)

Let Sum2 = Sum2 + Answer2

End For

If (Sum2 = 10)

Output on the same line as the last Output: “A”

Else If (Sum2 = 11)

Output on the same line as the last Output: “B”

Else If (Sum2 = 12)

Output on the same line as the last Output: “C”

Else If (Sum2 = 13)

Output on the same line as the last Output: “D”

Else If (Sum2 = 14)

Output on the same line as the last Output: “E”

Else If (Sum2 = 15)

Output on the same line as the last Output: “F”

Else Output on the same line as the last Output: (Sum2)

End If

Else

For (Position = 0, Position < Length, Position = Position + 1)

CharAt is the value of the character in the UserInput at a current (Position)

Let N = N – 1

Let Answer = (CharAt * 2(N))

Let Sum = Sum + Answer

End For

If (Sum = 10)

Output on the same line as the last Output: “A”

Else If (Sum = 11)

Output on the same line as the last Output: “B”

Else If (Sum = 12)

Output on the same line as the last Output: “C”

Else If (Sum = 13)

Output on the same line as the last Output: “D”

Else If (Sum = 14)

Output on the same line as the last Output: “E”

Else If (Sum = 15)

Output on the same line as the last Output: “F”

Else Output on the same line as the last Output: (Sum)

End If

End If

End If

CS1809

Assignment 2 – System Design and PrototypeConverter 3

Red Group 04

Stasha Lauria

By Sebastian Waring

The user will enter their binary number here

The user will choose what output they want from a drop down menu

The answer will be displayed next to the drop down menu.

top related