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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to convet decimal number base-12 number in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "strings"
)

// Converts a decimal number to base-12 and returns it as a string
func decimalToBase12(decimalNumber int) string {
    if decimalNumber == 0 {
        return "0"
    }

    digits := "0123456789AB" // Base-12 digits (A = 10, B = 11)
    var base12 []string

    for decimalNumber > 0 {
        remainder := decimalNumber % 12
        base12 = append(base12, string(digits[remainder]))
        decimalNumber /= 12
    }

    // Reverse to get the correct order
    for i, j := 0, len(base12)-1; i < j; i, j = i+1, j-1 {
        base12[i], base12[j] = base12[j], base12[i]
    }

    return strings.Join(base12, "")
}

func main() {
    decimalNumber := 100
    base12Number := decimalToBase12(decimalNumber)
    fmt.Printf("Base-12 representation: %s\n", base12Number)

    decimalNumber = 19621
    base12Number = decimalToBase12(decimalNumber)
    fmt.Printf("Base-12 representation: %s\n", base12Number)
}


/*
run:

Base-12 representation: 84
Base-12 representation: B431

*/

 



answered Sep 11, 2025 by avibootz

Related questions

...