11 votes
Accepted

Hexadecimal bytes as variable converted to binary bits

You cannot use the notation 16^^ with variable arguments, since it does not get "evaluated" like normal functions, but rather it is just a way of writing ...
Hausdorff's user avatar
  • 3,505
7 votes
Accepted

DigitCount[], but in negative bases

Background mathworld.wolfram.com contains entries for Negabinary, Negadecimal and Base, including Wolfram language code examples Base $(-2)$ Negabinary ...
rhermans's user avatar
  • 36.5k
7 votes
Accepted

Integer to Alpha Representation

I think you can use IntegerDigits directly if you add an offset, and then use the 3rd argument of IntegerDigits to only return ...
Carl Woll's user avatar
  • 131k
6 votes
Accepted

convert the BaseForm of 2 (binary data) to an array

IntegerDigits is for this: PadLeft[#, 3] & /@ Table[IntegerDigits[i, 2], {i, 0, 4}] {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {...
corey979's user avatar
  • 23.9k
5 votes

Using FromDigits to convert number strings to numbers

It looks to me that when you copied you copied the plain text form not the input form of the list of strings representing your hexadecimal numbers. Normally, copying form output cells gives the input ...
m_goldberg's user avatar
  • 108k
5 votes
Accepted

Why ImportByteArray when generate image from bytes

There are a couple of issues here. First, the full text of Image::imgarray sheds light on one issue: ...
rcollyer's user avatar
  • 34k
5 votes

Integer to Alpha Representation

A memoized recursive approach seems faster: ...
MarcoB's user avatar
  • 67.2k
5 votes

How can I convert the output of IntegerString[n, "Base64"] back into base 10?

Here's something you could try. First, build the mapping to "decode" a Base64 encoding as if it represented a digit sequence: ...
lericr's user avatar
  • 28k
5 votes

Extracting powers of a sum

Use IntegerDigits instead of BaseForm. (* some prior computations... *) n = 3; kl = {1, 2, 3}; value = Sum[n^k, {k, kl}]; Now, assuming that you know what n was ...
lericr's user avatar
  • 28k
4 votes

Hexadecimal bytes as variable converted to binary bits

FromDigits is fast but it does not catch invalid inputs. IntegerDigits[FromDigits["C12BZ", 16], 2] {1, 1, 0, 0, 0, 0,...
Suba Thomas's user avatar
  • 8,741
4 votes

Using FromDigits to convert number strings to numbers

Welcome to the world of coding! Objects like numbers and words have different types in programming languages like Mathematica. It's important to pay attention to the types of the objects you create. ...
Chris Nadovich's user avatar
4 votes
Accepted

Problem defining a function that takes a binary input to its decimal form

The code binarytodecimal[b_String] := NumberForm[ToExpression["2^^"<>b], 20]; does what you want. For example ...
Somos's user avatar
  • 4,897
4 votes

DigitCount[], but in negative bases

Here is my solution which uses a loop format mimicking the solutions on Wikipedia ...
IntroductionToProbability's user avatar
4 votes

Speed up counting of digits in binary number

Please investigate how this technique fares in your application. Let's say: SeedRandom[1]; binSequence = RandomInteger[{0, 1}, 20] {1, 1, 0, 1, 0, 0, 0, 1, 0, 1, ...
Syed's user avatar
  • 53.2k
4 votes

Find a number's digits in an arbitrary base

Alternatively to IntegerDigits you can "write a program" yourself. Something like this will work for positive numbers: ...
BlacKow's user avatar
  • 6,428
4 votes

Function for converting to base b, taking derivative with respect to b and evaluating at b

For your particular problem: D[IntegerDigits[37, 5] {b^2, b, 1}, b] /. {b -> 5} // Total 12 In general you can create a function: ...
bill s's user avatar
  • 69k
4 votes
Accepted

How do I check if the base-$b$ representation of my number contains the same digits?

As @HenrikSchumacher mentioned, IntegerDigits works: ...
Αλέξανδρος Ζεγγ's user avatar
4 votes
Accepted

How can I convert an integer to a binary list?

Try IntegerDigits: IntegerDigits[6, 2] {1, 1, 0}
kglr's user avatar
  • 395k
3 votes

Integer to Alpha Representation

Mod and Quotient support offsets, allowing: ...
Mr.Wizard's user avatar
  • 271k
3 votes
Accepted

Function for converting to base b, taking derivative with respect to b and evaluating at b

f[n_, b_] := Module[{dig}, dig = IntegerDigits[n, b]; D[dig.Table[x^i, {i, Length@dig - 1, 0, -1}], x] /. x -> b ] Maybe a different example for ...
corey979's user avatar
  • 23.9k
3 votes

Function for converting to base b, taking derivative with respect to b and evaluating at b

db[n_Integer, b_Integer] := FromDigits[(# Range[Length@#, 1, -1]) &@ Most@IntegerDigits[n, b], b] or ...
george2079's user avatar
  • 38.9k
3 votes
Accepted

How to preserve real number's precision

This may seem counter-intuitive, but what works is to rationalize the number first, Rationalize[523.502] (* 261751/500 *) This allows us to take advantage of the ...
Jason B.'s user avatar
  • 68.4k
3 votes

How to calculate the rightmost 1 and the leftmost 1 in the binary representation of a large number x?

You can use IntegerLength and IntegerExponent: SeedRandom[77]; x = RandomInteger[{1, 2^64}] ...
kglr's user avatar
  • 395k
3 votes

Speed up counting of digits in binary number

The post linked by MarcoB contains a link to this Wikipedia page which is very illuminating: https://en.wikipedia.org/wiki/Hamming_weight There I found also the very useful remark that a population ...
Henrik Schumacher's user avatar
3 votes

Convert List of integers to Hex

Define a function to convert a number to a 64-bit hex string while respecting two's complement representation: (thanks to Michael for simplifying!) ...
Roman's user avatar
  • 47.4k
2 votes
Accepted

Conversion to expression in base 17 with particular needs

Perhaps you can do: ...
Carl Woll's user avatar
  • 131k
2 votes

Base 12 input and output without ^^ or BaseForm

Updated to work with strings instead of boxes One idea is to create a "Duodecimal" style that automatically interprets strings as base 12 integers, and outputs the result in ...
Carl Woll's user avatar
  • 131k
2 votes

Splitting a binary number into smaller parts and converting each smaller part back to decimal

string = "1111 01001000100110001101010 111111 0000101101110110011100101"; FromDigits[#, 2] & /@ StringSplit[string] {15, 2378858, 63, 1502437} Update: To ...
kglr's user avatar
  • 395k
2 votes

Splitting a binary number into smaller parts and converting each smaller part back to decimal

d = {1111, 01001000100110001101010, 111111, 0000101101110110011100101}; FromDigits[#, 2] & /@ IntegerDigits@d {15, 2378858, 63, 1502437}
OkkesDulgerci's user avatar
1 vote

Splitting a binary number into smaller parts and converting each smaller part back to decimal

FromDigits[#, 2] & /@ (ToString /@ d) where d = {1111, 01001000100110001101010, 111111, 0000101101110110011100101}
David G. Stork's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible