The Gateway to Computer Science Excellence

+32 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**'

Correct Answer: $B$

+20

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?

+1

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?

0

@Bikram sir, so even if it were base 16 rather than 64, then also padding will be done at RHS? Do we pad always at RHS when performing encoding since we will never know the size of data?

0

I think what you are saying is we have to consider the situation when computer is sending bits one by one and we have no idea what will be the size of data so we will append at end, am I correct? and then what was that case when we were appending 0's on LHS while converting binary to hexadecimal?

0

@ayush.5

https://gateoverflow.in/3515/gate2007-it-70?show=144761#c144761

so even if it were base 16 rather than 64, then also padding will be done at RHS...

https://gateoverflow.in/3515/gate2007-it-70?show=151195#c151195

https://gateoverflow.in/3515/gate2007-it-70?show=144761#c144761

so even if it were base 16 rather than 64, then also padding will be done at RHS...

https://gateoverflow.in/3515/gate2007-it-70?show=151195#c151195

+13 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.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,644 questions

56,523 answers

195,607 comments

101,286 users