The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+18 votes

You are given the following four bytes :

10100011 | 00110111 | 11101001 | 10101011 |

Which of the following are substrings of the base $64$ encoding of the above four bytes?

- $\text{zdp}$
- $\text{fpq}$
- $\text{qwA}$
- $\text{oze}$

+26 votes

Best answer

Your are given the following four bytes :

$10100011\qquad 00110111\qquad 11101001\qquad 10101011 =32 +\text{ADD 4 0's}=36$

accoding to wikipedia, make pair of 6 should be made. https://en.wikipedia.org/wiki/Base64

$101000\qquad 110011\qquad 011111\qquad 101001\qquad 101010\qquad 11\mathbf{0000}$

$40$ $51$ $31$ $41$ $42$ $48$

$o$ $z$ $f$ $p$ $q$ $w$ from $\text{base-64}$ table.

Now, the longest substring will be from option checking is '**fpq**'

+16

why it is padded at right side to left side ?

To pad it in the left side **we need to know the length of the data in advance**.Which is not possible to know in advance so padding is require at right side.

We know length is 6 bit as we get from base 64 table .

But if the data is 24 bits then no problem because no padding.

If data is 32 bit then 6 + 6 + 6 + 6 + 6 + 2

Then we have to pad 4 0's with last part .

If data is 40 bits then 6 +6+6+6+6+6+4

Then we have to pad 2 0's with last part .

So we cannot predict from the start whether 4 zero or 2 zero will be padded.

It is only in the end of the data ,i.e on the right side where we know how much to pad. This is the only reason for padding at RHS rather than LHS .

0

@Bikram sir.Then why cant we do padding on RHS for hexa decimal ?

If i have 10. then we will pad two zeros on left and not on right.Can you tell the difference between this?

If i have 10. then we will pad two zeros on left and not on right.Can you tell the difference between this?

0

each hexadecimal digit represents four binary digits (bits),

In hexa decimal we know the length of the data in which size we need to convert in advance so it is padded at left side.

But here in this question we don't know in which size we neeed to convert so padded at right side.

+5

Hexa is base 16 and we pair group of 4 bits

Octal is base 8 and we pair group of 3 bits

With similar assumption If base is 64 we will pair 6 bits?

Octal is base 8 and we pair group of 3 bits

With similar assumption If base is 64 we will pair 6 bits?

0

If base is 64 we will pair 6 bits , yes , it is fine..

But if the data is 24 bits then no problem because no padding require.

If data is 32 bit then 6 + 6 + 6 + 6 + 6 + 2

Then we have to pad 4 0's with last part .

If data is 40 bits then 6 +6+6+6+6+6+4

Then we have to pad 2 0's with last part .

So we cannot predict from the start whether 4 zero or 2 zero will be padded.

It is only in the end of the data ,i.e on the right side where we know how much to pad. This is the only reason for padding at RHS rather than LHS .

+2

but sir in the question we are already told that we need to convert it to base 64. so we know that it is to be converted to base 64 wthen why padding on right?

0

sir i dont understand why bits are padded on rhs?

sir you said that to pad a bits in rhs **we need to know the length of the data in advance**.

but sir when we pad bits in rhs we also need to know data length in advance.

you said if we have 32 bits , if we know about bits we can pad after 32 bit in lhs.

please clarify sir i dont know where i am wrong.

+1

@ Bikram sir...when we are converting binary to hexa or octal or other then padding is done left side but here

data is given in binary form and we are converting into base 64( to represent 64..we need 6 bits) then it should be also using left padding ???

0

0

@Bikram Sir, do we need to remember the base 64 table?, Also if they ask problems on base 128 table, how to develop it?

+10 votes

+1

first 6 bits are 101000 which is equivalent to 40 that corresponds to 'o' then why are you writing it as c ?

0

Your are given the following four bytes :

10100011 00110111 11101001 10101011 =32 **+** **ADD 4 0's** = 36

accoding to wikipedia pair of 6 should be made. https://en.wikipedia.org/wiki/Base64

101000 110011 011111 101001 101010 11**0000**

40 51 31 41 42 48

o z f p q w from base 64 table.

now the longest substring will be from option checking is '**fpq**'

0 votes

As it is asking substring of the base 64 and the given numbers are binary, so we need to make it pair of 6,

Because 2^6=64,

So the pairs will be 101000 | 110011 | 011111 | 101001 | 101010 | 11

The last number has only 2 bits so we will use padding so it'll be 110000

So they will be 40 51 31 41 42 and 48

Which is equals to o z f p q w ( see the base table of 64)

so the substring is "fpq".

Because 2^6=64,

So the pairs will be 101000 | 110011 | 011111 | 101001 | 101010 | 11

The last number has only 2 bits so we will use padding so it'll be 110000

So they will be 40 51 31 41 42 and 48

Which is equals to o z f p q w ( see the base table of 64)

so the substring is "fpq".

- All categories
- General Aptitude 1.5k
- Engineering Mathematics 7.1k
- Digital Logic 2.7k
- Programming & DS 4.9k
- Algorithms 4.2k
- Theory of Computation 5.3k
- Compiler Design 2.1k
- Databases 4k
- CO & Architecture 3.5k
- Computer Networks 4k
- Non GATE 1.4k
- Others 1.5k
- Admissions 559
- Exam Queries 555
- Tier 1 Placement Questions 23
- Job Queries 69
- Projects 18

47,935 questions

52,336 answers

182,393 comments

67,819 users