Reputation: 15
I want to remove few digits from a 24-bit binary
number and convert it to 18-bit binary
number.
For example:
if Binary number
bin24=111100111011111000100111
I want to remove bits 23:22
, 15:14
and 7:6
and the output should be
bin18=110011111110100111
I know I can do this using substr()
and concatenate. Just wanted to know if I can do this in one line?.
Upvotes: 1
Views: 104
Reputation: 118148
my $bin18 = reverse join '', (reverse ($bin24 =~ /([01])/g))[0 .. 5, 8 .. 13, 16 ..21];
and other variations on the theme.
Upvotes: 1