vkorbes / aprendago

Curso completo em português da linguagem Go, de zero a ninja! 🇧🇷
http://aprendago.com
1k stars 179 forks source link

Exercício: Capítulo 5, Exercício 4 (Nível: 2) #13

Open vkorbes opened 3 years ago

vkorbes commented 3 years ago

Exercício: Capítulo 5, Exercício 4 (Nível: 2)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

diegoparra commented 3 years ago

https://play.golang.org/p/Y3JVPXvtoXt

andersoncleyson commented 3 years ago

https://play.golang.org/p/5ccToCkp0yH

basquegran2 commented 3 years ago

https://play.golang.org/p/6CTM6_6kj8z

guifeliper commented 3 years ago
package main

import (
    "fmt"
)

const x = 10

func main() {
    fmt.Printf("decimal=%d, binario=%b, hexadecimal= %#x\n", x, x, x)

    y := x << 1
    fmt.Printf("decimal=%d, binario=%b, hexadecimal= %#x", y, y, y)
}
Julian-ie commented 3 years ago

https://play.golang.org/p/_fahIMXA_4h

thiagoalgo commented 3 years ago

https://play.golang.org/p/DlCVj_fFON5

viniciussanchez commented 3 years ago

https://play.golang.org/p/SJ5ImKiTdkF

tomxdev commented 3 years ago
package main

import "fmt"

func main() {
    x := 150
    fmt.Printf("DECIMAL: %d\t BINARY: %b\t HEXADECIMAL: %#x\n", x, x, x)

    y := x >> 1
    fmt.Printf("DECIMAL: %d\t BINARY: %b\t HEXADECIMAL: %#x", y, y, y)
}
an4kein commented 3 years ago

https://play.golang.org/p/uQ5ffktkjjF

Achei interessante essa parada de deslocar bits, em um futuro nao muito distante posso utilizar isso para ofuscar um payload.

Em vez de escrever 600x2=1200 eu posso simplesmente usar o deslocamento de 1 bit para esquerda e chego no mesmo resultado de 1200 😈

victorinno commented 3 years ago

https://play.golang.org/p/mevPs8eHLtS

ygorsimoes commented 3 years ago
package main

import "fmt"

func main() {
    numero := 10
    fmt.Printf("Decimal: %d\n", numero)
    fmt.Printf("Binário: %b\n", numero)
    fmt.Printf("Hexadecimal: %#x\n\n", numero)

    numeroComBitDeslocado := numero << 1
    fmt.Printf("Decimal: %d\n", numeroComBitDeslocado)
    fmt.Printf("Binário: %b\n", numeroComBitDeslocado)
    fmt.Printf("Hexadecimal: %#x", numeroComBitDeslocado)
}

Output:

Decimal: 10
Binário: 1010
Hexadecimal: 0xa

Decimal: 20
Binário: 10100
Hexadecimal: 0x14
JPauloMoura commented 3 years ago
package main

/*
Crie um programa que:
- Atribua um valor int a uma variável
- Demonstre este valor em decimal, binário e hexadecimal
- Desloque os bits dessa variável 1 para a esquerda, e atribua o resultado a outra variável
- Demonstre esta outra variável em decimal, binário e hexadecimal
*/
import "fmt"

func main() {
    v := 60
    fmt.Printf("| %d | %b | %#x |\n\n", v, v, v)

    v2 := v << 1
    fmt.Printf("| %d | %b | %#x |", v2, v2, v2)
}

Resolução do Exercício

Lucasmirandar commented 3 years ago

https://play.golang.org/p/Z5VTuDLFo2B

andersoncleyson commented 2 years ago
package main

import "fmt"

func main(){
    x := 20
    fmt.Printf("%d\t %b\t %#x\n", x, x, x)

    y := x << 1
    fmt.Printf("%d\t %b\t %#x\n", y, y, y)
}
guilherme-de-marchi commented 2 years ago
package main

import "fmt"

func main() {

    var param_1 int
    fmt.Print("Valor: ")
    fmt.Scan(&param_1)

    fmt.Printf("\nDecimal: %d | Hexadecimal: %x | Binario: %b\n", param_1, param_1, param_1)

    param_2 := param_1 << 1

    fmt.Printf("\nDecimal: %d | Hexadecimal: %x | Binario: %b\n", param_2, param_2, param_2)

}

Output:

Valor: 2

Decimal: 2 | Hexadecimal: 2 | Binario: 10

Decimal: 4 | Hexadecimal: 4 | Binario: 100
ltbatis commented 2 years ago

https://play.golang.org/p/N18f47df_KF

CarlosSMA commented 2 years ago
package main

import "fmt"

func main() {
    x := 10
    fmt.Println("-=-=-=-=-=-=-=-=- Variável 1 -=-=-=-=-=-=-=-=-")
    fmt.Printf("Binário - %b\nDecimal - %d\nHexadecimal - %#x\n\n", x, x, x)
    y := x << 1
    fmt.Println("-=-=-=-=-=-=-=-=- Variável 2 -=-=-=-=-=-=-=-=-")
    fmt.Printf("Binário - %b\nDecimal - %d\nHexadecimal - %#x\n", y, y, y)
}

Output

-=-=-=-=-=-=-=-=- Variável 1 -=-=-=-=-=-=-=-=-
Binário - 1010
Decimal - 10
Hexadecimal - 0xa

-=-=-=-=-=-=-=-=- Variável 2 -=-=-=-=-=-=-=-=-
Binário - 10100
Decimal - 20
Hexadecimal - 0x14
AlissonAp commented 2 years ago

https://go.dev/play/p/ix8s_LvE8L9

CaueFarias commented 2 years ago

https://go.dev/play/p/GmJqDJWeFbD

Matheus-Natanael commented 2 years ago

package main

import ( "fmt" )

var x int = 10

func main() { fmt.Printf("Decimal x: %d\nBinário x: %b\nHexadecimal x: %#x\n", x, x, x)

y := x >> 1
fmt.Printf("Decimal y: %d\nBinario y: %b\nHexadecimal y: %#x",
    y, y, y)

}

gustavomfc commented 2 years ago

package main

import "fmt"

func main() { n := 42

fmt.Printf("%v em Decimal = %d\n", n, n)
fmt.Printf("%v em Binário = %b\n", n, n)
fmt.Printf("%v em Hexa = %x\n", n, n)

z := n << 1

fmt.Printf("%v em Decimal = %d\n", z, z)
fmt.Printf("%v em Binário = %b\n", z, z)
fmt.Printf("%v em Hexa = %x\n", z, z)

}

M3L1M commented 1 year ago

var a int = 200

func main() { fmt.Printf("%d\t%b\t%#x\n", a, a, a)

var b = a << 1
fmt.Printf("%d\t%b\t%#x\n", b, b, b)

}

an4kein commented 1 year ago
https://go.dev/play/p/EpgVukL9hPA

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

var newNumber int

func main() {
    number := 200
    fmt.Printf("%v\n%#b\n%#x", number, number, number)
    newNumber = number << 1
    fmt.Println()
    fmt.Printf("%v\n%#b\n%#x", newNumber, newNumber, newNumber)
}

/*
- Crie um programa que:
    - Atribua um valor int a uma variável
    - Demonstre este valor em decimal, binário e hexadecimal
    - Desloque os bits dessa variável 1 para a esquerda, e atribua o resultado a outra variável
    - Demonstre esta outra variável em decimal, binário e hexadecimal
*/
---------------------------------------------------------------------------------------------------------------------------------------------
200
0b11001000
0xc8
400
0b110010000
0x190
Program exited.
---------------------------------------------------------------------------------------------------------------------------------------------
1r4mos commented 3 months ago

https://go.dev/play/p/SHxzxbNotsm

DominMFD commented 2 months ago

https://go.dev/play/p/QytwAwH17pd

Vitor-Zen commented 1 month ago

https://go.dev/play/p/YbqBiJy9l2v