How would I view/use Number Base from 2 to 256

Data at rest is binary.
When I read a file, it is presented in an output, like print() in hex. Julia converts the binary state of the file and outputs the hex info.
This isn’t the behavior I need. I would like to take the state the file exists in, see it as is, and see it in different bases, like, base4, base8 base9, base10, base16, base60, base64, base128, base256.
How do I change the output of UInt8 to provide another base?

Data in storage Base2.
Data running through the CPU Base2.
IP Addresses, color choices are base256.
Mac Addresses are Base16.
Code obfuscation often uses base64.

file.txt exists as Base2. Placed into a vector, what is the base?
When I read or open stream to print, then it is presented in Base16.
My goal is to see file.txt as base2->base256 as I need.
The function digits() only works between base2 to base36.
How do I view it in it’s native state and transform it into other states?
I’m lost in translation.

Are you sure about that?

julia> digits(typemax(Int), base=256)
8-element Vector{Int64}:
 255
 255
 255
 255
 255
 255
 255
 127
base(base, n, [pad])

Convert an integer to a string in the given base, optionally specifying a number of digits to pad to. The base can be specified as either an integer, or as a UInt8 array of character values to use as digit symbols.

@Juliahub

Common mistake example:

julia> base(1, 42)
ERROR: ArgumentError: base 1 must be in the range 2 to 36

In this example, the base 1 is not within the valid range of 2 to 36. The base must be specified within this range to convert the integer to a string representation.

This no longer works in 1.11.6
I can’t replicate this on my current setup.
Originally I used 1.11.5 when I began exploring.

Printing out text files gives the data as hex values, I was interested in representing them in other commonly used bases, like 64, 256, as alternatives.

This is getting on the weird side. Julia used to have a function called base until Julia 0.6, which was deprecated in 0.7 (for string) and removed in Julia 1.0. At no point did the docstring look like in the commented post.

In fact, the only place I can find that formulation in a web search is on a site called jlhub.com. I’ve never heard about it before but it is not Juliahub and in all likelihood an AI generated spam site.

1 Like

AI slop sites producing misleading information for novice researchers targeting Julia programming.
AyeYah.

Using DDG I was attempting to find out how to represent information in alternative bases. Didn’t realize there were wormholes to bizarroverses.

Note to self. cc Don’t use that site.

Thanks Mason,
Apparently digits() doesn’t have any limits in the range I would like to use it.
I will have to review what I’m trying to accomplish and see how I can make the necessary changes.
Thanx

1 Like