forked from root/public
hamza
2 years ago
committed by
David Mata
1 changed files with 42 additions and 0 deletions
@ -0,0 +1,42 @@ |
|||||||
|
## binary-addition |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function named `BinaryAddition(int,int)` that takes two integers and returns the sum of the two in binary in an array of `int`. |
||||||
|
- If the sum is negative return `nil` value. |
||||||
|
- convert the argument to binary then add the two binary numbers together |
||||||
|
|
||||||
|
### Expected function |
||||||
|
```go |
||||||
|
func BinaryAddition(a int, b int) []int { |
||||||
|
// your code here |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import "fmt" |
||||||
|
|
||||||
|
|
||||||
|
func main(){ |
||||||
|
fmt.Println(BinaryAddition(1,1)) |
||||||
|
fmt.Println(BinaryAddition(1,2)) |
||||||
|
fmt.Println(BinaryAddition(1,3)) |
||||||
|
fmt.Println(BinaryAddition(4,4)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
and the output should be: |
||||||
|
|
||||||
|
```console |
||||||
|
$ go run . |
||||||
|
[1 0] |
||||||
|
[0 1 1] |
||||||
|
[1 0 0] |
||||||
|
[0 1 1] |
||||||
|
[1 0 0] |
||||||
|
[1 0 1] |
||||||
|
``` |
Loading…
Reference in new issue