Sum Of Two Numbers. - Brainfuck.
How to read input from the user?
‘,’ command is used to read the input from the user.
How to calculate the sum of two numbers?
First of all, when you read the input from the user, it is stored in the cells as an ASCII number.
Decimal Number
|
ASCII Equivalent
|
0
|
48
|
1
|
49
|
2
|
50
|
3
|
51
|
4
|
52
|
5
|
53
|
6
|
54
|
7
|
55
|
8
|
56
|
9
|
57
|
By subtracting the ASCII equivalent of a number with 48 we can get the actual number.
0 = 48 – 48
1 = 49 – 48
2 = 50 – 48
3 = 51 – 48
4 = 52 – 48
5 = 53 - 48
6 = 54 - 48
7 = 55 - 48
8 = 56 – 48
9 = 57 – 48
After reading the two numbers, we should take them to their decimal equivalents.
Comments
Post a Comment