Convert vector of numeric values into a vector of equivalent 8-bit ‘int8’ binary values
Hi,
I am trying to convert a 1×4 numeric vector into the equivalent 8-bit binary ‘int8’ value which is also a 1×4 vector, however I am creating a 1×8 vector which appears to be the binary value of 8 which is the second element.
So each numeric element I want to convert to it’s 8-bit ‘int8’ binary equivalent and store it in the same element in another vector.
Assuming I have not messed up my Two’s Compliment I am expecting the row vector to be displayed as;
[10011110 01111000 01001111 00001000]
Any help would be appreciated.
x = [-98 8 49 120];
y = zeros(1,length(x));
for idx = 1:length(x)
y = bitget(x(idx),8:-1:1,’int8′);
end
disp(y)Hi,
I am trying to convert a 1×4 numeric vector into the equivalent 8-bit binary ‘int8’ value which is also a 1×4 vector, however I am creating a 1×8 vector which appears to be the binary value of 8 which is the second element.
So each numeric element I want to convert to it’s 8-bit ‘int8’ binary equivalent and store it in the same element in another vector.
Assuming I have not messed up my Two’s Compliment I am expecting the row vector to be displayed as;
[10011110 01111000 01001111 00001000]
Any help would be appreciated.
x = [-98 8 49 120];
y = zeros(1,length(x));
for idx = 1:length(x)
y = bitget(x(idx),8:-1:1,’int8′);
end
disp(y) Hi,
I am trying to convert a 1×4 numeric vector into the equivalent 8-bit binary ‘int8’ value which is also a 1×4 vector, however I am creating a 1×8 vector which appears to be the binary value of 8 which is the second element.
So each numeric element I want to convert to it’s 8-bit ‘int8’ binary equivalent and store it in the same element in another vector.
Assuming I have not messed up my Two’s Compliment I am expecting the row vector to be displayed as;
[10011110 01111000 01001111 00001000]
Any help would be appreciated.
x = [-98 8 49 120];
y = zeros(1,length(x));
for idx = 1:length(x)
y = bitget(x(idx),8:-1:1,’int8′);
end
disp(y) int8, bitget, binary MATLAB Answers — New Questions