aprendago icon indicating copy to clipboard operation
aprendago copied to clipboard

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

Open vkorbes opened this issue 4 years ago • 27 comments

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!

vkorbes avatar Sep 30 '20 17:09 vkorbes

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

diegoparra avatar Oct 04 '20 19:10 diegoparra

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

andersoncleyson avatar Oct 06 '20 19:10 andersoncleyson

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

basquegran2 avatar Nov 10 '20 18:11 basquegran2

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)
}

guifeliper avatar Nov 28 '20 17:11 guifeliper

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

Julian-ie avatar Dec 27 '20 23:12 Julian-ie

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

thiagoalgo avatar Jan 10 '21 00:01 thiagoalgo

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

viniciussanchez avatar Jan 11 '21 11:01 viniciussanchez

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)
}

tomxdev avatar Jan 27 '21 10:01 tomxdev

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 😈

an4kein avatar Feb 09 '21 00:02 an4kein

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

victorinno avatar Feb 15 '21 16:02 victorinno

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

ygorsimoes avatar Mar 15 '21 00:03 ygorsimoes

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

JPauloMoura avatar May 22 '21 22:05 JPauloMoura

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

Lucasmirandar avatar Jun 02 '21 11:06 Lucasmirandar

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)
}

andersoncleyson avatar Aug 09 '21 01:08 andersoncleyson

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

guilherme-de-marchi avatar Aug 24 '21 20:08 guilherme-de-marchi

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

ltbatis avatar Nov 15 '21 16:11 ltbatis

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

CarlosSMA avatar Dec 05 '21 23:12 CarlosSMA

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

AlissonAp avatar Feb 07 '22 23:02 AlissonAp

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

CaueFarias avatar Feb 08 '22 19:02 CaueFarias

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)

}

Matheus-Natanael avatar May 16 '22 15:05 Matheus-Natanael

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)

}

gustavomfc avatar May 26 '22 02:05 gustavomfc

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)

}

M3L1M avatar Feb 09 '23 02:02 M3L1M

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.
---------------------------------------------------------------------------------------------------------------------------------------------

an4kein avatar May 12 '23 17:05 an4kein

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

1r4mos avatar Apr 24 '24 23:04 1r4mos

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

DominMFD avatar May 13 '24 19:05 DominMFD

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

Vitor-Zen avatar Jun 26 '24 14:06 Vitor-Zen