Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,406 questions

56,397 answers

573 users

How to convert text to binary code in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "strconv"
    "strings"
)

func text2bin(txt string) string {
    var bin strings.Builder
    
    for _, ch := range txt {
        binary := strconv.FormatInt(int64(ch), 2)
        bin.WriteString(fmt.Sprintf("%08s", binary) + " ")
    }
    
    return bin.String()
}

func main() {
    fmt.Println(text2bin("Go Programming"))
}



/*
run:

01000111 01101111 00100000 01010000 01110010 01101111 01100111 01110010 01100001 01101101 01101101 01101001 01101110 01100111

*/

 



answered Nov 18, 2024 by avibootz

Related questions

1 answer 148 views
1 answer 309 views
1 answer 162 views
1 answer 149 views
1 answer 158 views
1 answer 155 views
...