MATL, 7 bytes
BJ*Y'^s
###How it works
How it works
Consider input 4538 for example.
B % Implicit input. Convert to binary
% STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
% STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
% STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
% STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
% STACK: -1+1i
MATL, 7 bytes
BJ*Y'^s
###How it works
Consider input 4538 for example.
B % Implicit input. Convert to binary
% STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
% STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
% STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
% STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
% STACK: -1+1i
MATL, 7 bytes
BJ*Y'^s
How it works
Consider input 4538 for example.
B % Implicit input. Convert to binary
% STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
% STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
% STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
% STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
% STACK: -1+1i
MATL, 7 bytes
BJ*Y'^s
###How it works
Consider input 4538 for example.
B % Implicit input. Convert to binary
% STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
% STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
% STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
% STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
% STACK: -1+1i
MATL, 7 bytes
BJ*Y'^s
###How it works
B % Implicit input. Convert to binary
J* % Multiply by 1i
Y' % Run-length encoding
^ % Power, element-wise
s % Sum of array. Implicit display
MATL, 7 bytes
BJ*Y'^s
###How it works
Consider input 4538 for example.
B % Implicit input. Convert to binary
% STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
% STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
% STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
% STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
% STACK: -1+1i
MATL, 7 bytes
BJ*Y'^s
###How it works
B % Implicit input. Convert to binary
J* % Multiply by 1i
Y' % Run-length encoding
^ % Power, element-wise
s % Sum of array. Implicit display