図1は,8×8画素の白黒の画像例である。この図に対して,白を0,黒を1として表すと,図2に示すように8ビットのビット列が8行あるディジタルデータとして,画像データを表現することができる。 文字データしか送れない通信で画像データを送ろうとする場合,画像データを文字データであるかのように変換して通信する必要がある。 また,文字データと比べてデータ量の大きい画像データを効率よく通信するために,データを圧縮して送るという工夫がなされる。図2のビット列を左上から順に見ていくと,0が10個続き,次に1が34個続き,その次に0が20個続いていることが分かる。この同じ値が続く個数のことをランレングスという。これを利用して画像データを圧縮する方法を考える。 次に示す画像データの表現方法は,画像データを文字データに変換するものである。図2の画像データの中の 9~12 ビット(2行目の先頭4ビット)のビット列は,どの文字として表現されるか。 〔画像データの表現方法〕 (1) 画像データのビット列を4ビットずつ取り出し,それぞれの先頭に4ビットの値“0100”を補い,8ビットで表現する。 (2) (1)で求めた各8ビットの値を JIS X 0201 の文字コードに対応する文字で表現する。01000000, 01000001, 01000010, …, 01001111 の8ビットの値は,JIS X 0201 の文字コード体系では,文字@, A, B, …, O に対応する。
平成24年度 秋期 ITパスポート試験 問93
This question's explanation and your answers so far.
問 93
Incorrectア
@ is 01000000, that is, the character corresponding to lower 4 bits of 0000. In Figure 2, the 4-bit groups that are 0000 are those consisting only of white pixels, such as the 1st row (bits 1 to 4 or bits 5 to 8) and the 7th and 8th rows, not bits 9 to 12. Reading bits 9 to 12 as 0000 is the mistake of overlooking that the 2nd row begins with 00111111 and simply answering with the value of the 1st row.
Incorrectイ
B is 01000010, whose lower 4 bits are 0010. The first 4 bits of the 2nd row in Figure 2 are 0011, not 0010. A typical mistake is to count @ as the 1st character instead of the 0th and thus pick the character one place earlier (0011 is 3 in decimal, yet it is counted as the 3rd character, B). You need to confirm that the correspondence table starts from 01000000 = @, that is, that counting starts from 0.
- ウ
正解 Figure 2 represents the 8×8-pixel image of Figure 1 as a bit string, taking white = 0 and black = 1, with 8 bits per row and 8 rows in total. The actual arrangement, from top to bottom, is 00000000 / 00111111 / 11111111 / 11111111 / 11111111 / 11110000 / 00000000 / 00000000. Bits are counted in order starting from the top left, so the 1st row is bits 1 to 8 and the 2nd row is bits 9 to 16; therefore bits 9 to 12 asked about in the question (the first 4 bits of the 2nd row) are 0011. Applying representation method (1) to this and prepending 0100 gives the 8-bit value 01000011. Representation method (2) provides the correspondence in which 01000000 is @, and each increase of 1 in the value advances the character to A, B, C, ..., O. In other words, the value of the lower 4 bits read as a binary number is exactly how many characters past @ to go. Since 0011 is 3 in decimal, counting @ (0), A (1), B (2), C (3) gives C. Therefore the correct answer is ウ, C. This scheme splits image data, which consists only of 0s and 1s, into groups of 4 bits and replaces each group with a printable character, so that an image can be sent even over a communication path that can carry only character data; it is the same idea as practical encoding schemes such as Base64.
Incorrectエ
O is 01001111, whose lower 4 bits are 1111. In Figure 2, the parts that become 1111 are those where black pixels run consecutively, such as rows 3 to 5; bits 9 to 12 are not among them. Reading bits 9 to 12 as 1111 is a mistake that occurs when you overlook the two white pixels (00) at the start of the 2nd row and take it for a row of black pixels only, or when you start counting bits from the 2nd row instead of the 1st row and end up shifted.
- Digitizing a black-and-white binary image: each pixel is mapped to one bit, white = 0 and black = 1, and lining them up row by row from the top left produces a bit string. The bit position is counted with a single running number over the whole image starting from the top left, so for an 8×8-pixel image, bits 9 to 12 are the first 4 bits of the 2nd row.
- Encoding that converts a bit string into characters: take 4 bits, prepend fixed high-order bits (0100 here), and map the result to consecutive characters in a character code table. If 01000000 = @ is taken as 0, the binary value of the lower 4 bits is directly the offset from @ (0=@, 1=A, 2=B, 3=C, ..., 15=O). This is the idea used to send images over a communication path that can carry only characters, and it belongs to the same family as Base64.