Is it possible to pack 5 bits in perl? [closed] - perl

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
For example, let's say I want to pack the following bits: 11111 which is 31 in decimal. How can I pack these 5 bits? I don't want to pack 8 bits or 1 byte. I need to pack only 5 bits; 11111
b5 "11111" doesn't seem to work for me.

works for me :
print oct "0b11111";
31
print ord(pack("b*","11111"));
31

Related

Simplify expression with unknown [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I am trying to simplify an expression which has an unknown varaible in it. I am doing it in scala and I am using case classes. The thing is I don't know how to handle an unknown variable e.g when 4 * 4 * x should become 16 * x but I don't know how to get the * x. Can anyone help

Intertwine 0s betweeen bits SystemVerilog [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to intertwine 0s between the bits of a variable. For example, imagine I have a variable a as follows
a = 1101
Then, I want to obtain the following result
b = 1_000000_1_000000_0_000000_1
That results from intertwining 6 0s betwen each bit of a. I was wondering if there was any elegant way of doing this in SystemVerilog. Any help is appreciated.
b = 0;
foreach (a[i]) b[i*7] = a[i];

How the matlab code gives a strange output and How to explain it? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I understand how the program works but I have a little bit of confusion. If anybody can explain, that will be great. The output is 21, 12. Does it work like 7*3=21 and 4*3=12?
mat=[7 11 3; 3:5];
[r,c]=size(mat);
for i=1:r
fprintf ('The sum is %d\n',sum(mat(i,:)))
end
mat(i,:) will give you all values in the first row of mat. In your example, this first row is [7 11 3], and the second row is [3 4 5]. The outputs you're seeing are the sums of all values in each row (7+11+3=21).

How I can insert data to table in MATLAB? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
The question is, I have this table: 1 2 3 4 5 6 7 8 9. I need turn it so:
1 2 3 3.5 4 4.5 5 5.5 6 6.5 7 8 9. What function in MATLAB allows me do that? Or I must make it by myself? I'm already understand my problem.
I guess an first order interpolation is what you want.
How to handle the funktion interp1 is explained in the Matlab Manual.

How do you print in swift only the even numbers from 1-10 in a range of 1...100? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Create another Range from 1 to 100. Use it to print out only the even numbers between 1 and 10. You'll need to use an if statement combined with your for loop to pull this off.
Consider this office hours. Try this:
for number in 1...100 {
if number%2 == 0 && number < 11 {
println(number)
}
}