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

...