Skip to main content

Numeral Systems - Binary

Updated 1 min readMarkdown
Part of series GopherLabs
Numeral Systems -  Binary
    package main

    import "fmt"

    func main() {
     fmt.Printf("%d - %b \n", 42, 42)
    }

Run{:.button.button--outline-success.button--pill}

Output:

 42 - 101010 

Program exited.

in above program the annotation verb %b formats a number in binary Ex:- which represent 101010 ( base 2 format) and the annotation verb %d formats a number in Base 10 Ex:which represent 42 ( base 10 format)

Integer cheatsheet for fmt

      %b    base 2
      %c    the character represented by the corresponding Unicode code point
      %d    base 10
      %o    base 8
      %q    a single-quoted character literal safely escaped with Go syntax.
      %x    base 16, with lower-case letters for a-f
      %X    base 16, with upper-case letters for A-F
      %U    Unicode format: U+1234; same as "U+%04

19 views

About the author

  • DevRel at StackGen | Formerly at Deepfence ,Tenable , Accurics | AWS Community Builder also Docker Community Award Winner at Dockercon2020 | CyberSecurity Innovator of Year 2023 award by Bsides Bangalore | Docker/HashiCorp Meetup Organiser Bangalore & Co-Author of Learn Lightweight Kubernetes with k3s (2019) , Packt Publication & also run Non Profit CloudNativeFolks / CloudSecCorner Community To Empower Free Education reach out me twitterhttps://twitter.com/sangamtwts or just follow on GitHub -> https://github.com/sangam14 for Valuable Resources

No comments yet. Be the first to comment.

More from this blog