Bit manipulation

Given two list of bit patterns and two bit strings, extract bits from the first string with the first pattern and place them in the second string with the second pattern. Draw a diagram above each value with numbers indicating the order of extraction and insertion (see tests for details). It should also work for text, not just binary digits. (see test 7)

IN

From: 010011010
Bits: 1:0, 6:4, 8
To:   000000000
Bits: 7:2

OUT

From:
3 2    1
^ /-\  /\
010011010

=100010

To:
 1
 /----\
010001000

IN

From: 0000011111
Bits: 9, 0, 8, 1, 7, 2, 6, 3, 5:4
To:   11111111110000000000
Bits: 14:5

OUT

From:
13579 8642
^^^^/\^^^^
0000011111

=0101010101

To:
     1
     /--------\
11111010101010100000

IN

From: 010011010
Bits: 6:4, 1:0, 8
To:   000000000
Bits: 7:2

OUT

From:
3 1    2
^ /-\  /\
010011010

=001100

To:
 1
 /----\
000110000

IN

From: 100100010000100000
Bits: 5:0, 10:6, 14:11, 17:15
To:   000000000000000000
Bits: 17:15, 14:11, 10:6, 5:0

OUT

From:
4  3   2    1
/-\/--\/---\/----\
100100010000100000

=100000100001000100

To:
1  2   3    4
/-\/--\/---\/----\
100000100001000100

IN

From: 100100010000100000
Bits: 5:0, 10:6, 14:11, 17:15
To:   000000000000000000
Bits: 17:12, 11:7, 6:3, 2:0

OUT

From:
4  3   2    1
/-\/--\/---\/----\
100100010000100000

=100000100001000100

To:
1     2    3   4
/----\/---\/--\/-\
100000100001000100

IN

From: 0011010010101100100101
Bits: 0, 2, 5, 9:8, 11, 13, 16, 19:18
To:   000000000000
Bits: 11, 8:0

OUT

From:
  8  7  6 5 4   3  2 1
  /\ ^  ^ ^ /\  ^  ^ ^
0011010010101100100101

=1111111111

To:
1  2
^  /-------\
100111111111

IN

From: saint
Bits: 4, 0, 3:1
To:   _____
Bits: 4, 2, 3, 1:0

OUT

From:
13  2
^/-\^
saint

=stain

To:
1324
^^^/\
satin

omg, this task is no fun

Tue Nov 17 01:00:30 2015


Leave a comment

Parsed as Markdown

Login to leave a comment