Skip to content

DecToBase etc. doesn't test conversion of 0 #4

@thomasweitzel

Description

@thomasweitzel

There's an important test case missing: DecToBase(0, ...). Same goes for BaseToDec.

In case of DecToBase(0, ...) an empty String is returned, which probably should be "0" instead.

I had to modify my recursive function - it now uses a helper function and duplicates some code:

const digits = "0123456789ABCDEF"

func _decToBase(dec, base int) string {
	if dec == 0 {
		return ""
	}
	digit := dec % base
	return _decToBase(dec/base, base) + string(digits[digit])
}

func DecToBase(dec, base int) string {
	digit := dec % base
	return _decToBase(dec/base, base) + string(digits[digit])
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions