Velocity Reviews > C++ > Shift left operator using pen and paper

# Shift left operator using pen and paper

Ian Collins
Guest
Posts: n/a

 08-02-2010
On 08/ 2/10 04:19 PM, BozonHE wrote:
> Hello. I have following question, can someone explain to me, how I can
> shift left some value using only pen and paper? Or is there some clever
> way without playing with binary numbers at all?

In decimal multiplication terms, what is the effect of shifting one
position to the left?

--
Ian Collins

red floyd
Guest
Posts: n/a

 08-02-2010
On 8/1/2010 9:19 PM, BozonHE wrote:
> Hello. I have following question, can someone explain to me, how I can
> shift left some value using only pen and paper? Or is there some clever
> way without playing with binary numbers at all?
>
>
> "After execution of the final assignment to ByteVal, what will be the
> numeric value of X?
>
> void main()
> {
> unsigned char X=7;
> X<<= 4;
> }
>
> A) 28
> B) 11
> C) 112
> D) 56
> "

Your answer may be found in the FAQ. Specifically, FAQ 5.2.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

BozonHE
Guest
Posts: n/a

 08-02-2010
Hello. I have following question, can someone explain to me, how I can
shift left some value using only pen and paper? Or is there some clever
way without playing with binary numbers at all?

"After execution of the final assignment to ByteVal, what will be the
numeric value of X?

void main()
{
unsigned char X=7;
X <<= 4;
}

A) 28
B) 11
C) 112
D) 56
"

Alf P. Steinbach /Usenet
Guest
Posts: n/a

 08-02-2010
* BozonHE, on 02.08.2010 06:19:
> Hello. I have following question, can someone explain to me, how I can
> shift left some value using only pen and paper? Or is there some clever
> way without playing with binary numbers at all?
>
>
> "After execution of the final assignment to ByteVal, what will be the
> numeric value of X?

For a guide to answering this, see Ian Collins' reply else-thread.

> void main()

This 'void' means that your educational material is sub-standard.

You should so inform your teacher (you can cite the C++ standard §3.6.1/2 "It
shall have a return type of 'int'...").

Also the lack of anything named 'ByteVal' in the code, as referred to by the
question, indicates sub-standard teaching material.

> {
> unsigned char X=7;
> X<<= 4;
> }
>
> A) 28
> B) 11
> C) 112
> D) 56
> "

Cheers & hth.,

- Alf

--
blog at <url: http://alfps.wordpress.com>

Stuart Golodetz
Guest
Posts: n/a

 08-02-2010
BozonHE wrote:
> Hello. I have following question, can someone explain to me, how I can
> shift left some value using only pen and paper? Or is there some clever
> way without playing with binary numbers at all?
>
>
> "After execution of the final assignment to ByteVal, what will be the
> numeric value of X?
>
> void main()
> {
> unsigned char X=7;
> X <<= 4;
> }
>
> A) 28
> B) 11
> C) 112
> D) 56
> "

This reminds me of the old joke: "There are 10 types of people - those
who understand binary and those who don't." That being said, here are
some base-neutral hints.

A number a_n ... a_1 a_0 in base b actually means:

\sum_{i=0}^n a_i b^i

Thus the decimal number 234 means:

2*(10^2) + 3*(10^1) + 4*(10^0)

Shifting a_n ... a_1 a_0 left by 1 yields:

a_n ... a_1 a_0 0

Or (if you prefer), a'_{n+1} a'_n ... a'_1 a'_0, where:

a'_{i+1} = a_i (for i >= 0)
a'_0 = 0

Thus, shifting 234 left by 1 in decimal yields:

2*(10^3) + 3*(10^2) + 4*(10^1) + 0*(10^0) = 2340

This is 10 times the original number. I wonder what would happen if you
did the same exercise in binary...?

Regards,
Stu

BozonHE
Guest
Posts: n/a

 08-02-2010
In article <i35gpn$kg$(E-Mail Removed)-september.org>,
http://www.velocityreviews.com/forums/(E-Mail Removed)lid says...
>
> On 8/1/2010 9:19 PM, BozonHE wrote:
> > Hello. I have following question, can someone explain to me, how I can
> > shift left some value using only pen and paper? Or is there some clever
> > way without playing with binary numbers at all?
> >
> >
> > "After execution of the final assignment to ByteVal, what will be the
> > numeric value of X?
> >
> > void main()
> > {
> > unsigned char X=7;
> > X<<= 4;
> > }
> >
> > A) 28
> > B) 11
> > C) 112
> > D) 56
> > "

>
> Your answer may be found in the FAQ. Specifically, FAQ 5.2.
>
> http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Dude, Im NOT asking for answer, but about left shifting using pen and
paper.

BozonHE
Guest
Posts: n/a

 08-02-2010
In article <i364qk$cc0$(E-Mail Removed)>, (E-Mail Removed) says...
>
> BozonHE wrote:
> > Hello. I have following question, can someone explain to me, how I can
> > shift left some value using only pen and paper? Or is there some clever
> > way without playing with binary numbers at all?
> >
> >
> > "After execution of the final assignment to ByteVal, what will be the
> > numeric value of X?
> >
> > void main()
> > {
> > unsigned char X=7;
> > X <<= 4;
> > }
> >
> > A) 28
> > B) 11
> > C) 112
> > D) 56
> > "

>
> This reminds me of the old joke: "There are 10 types of people - those
> who understand binary and those who don't." That being said, here are
> some base-neutral hints.
>
> A number a_n ... a_1 a_0 in base b actually means:
>
> \sum_{i=0}^n a_i b^i
>
> Thus the decimal number 234 means:
>
> 2*(10^2) + 3*(10^1) + 4*(10^0)
>
> Shifting a_n ... a_1 a_0 left by 1 yields:
>
> a_n ... a_1 a_0 0
>
> Or (if you prefer), a'_{n+1} a'_n ... a'_1 a'_0, where:
>
> a'_{i+1} = a_i (for i >= 0)
> a'_0 = 0
>
> Thus, shifting 234 left by 1 in decimal yields:
>
> 2*(10^3) + 3*(10^2) + 4*(10^1) + 0*(10^0) = 2340
>
> This is 10 times the original number. I wonder what would happen if you
> did the same exercise in binary...?
>

Can you show me example how to shift left int 7 by four using this
technique? Because I have problems with that.

Thank you.

ps. I'm NOT asking about answer for any "homwework" (in summer WTF?!).
I just forgot how to do such operations using pen and paper.

BozonHE
Guest
Posts: n/a

 08-02-2010
In article <(E-Mail Removed) >,
(E-Mail Removed) says...
>
> Hello. I have following question, can someone explain to me, how I can
> shift left some value using only pen and paper? Or is there some clever
> way without playing with binary numbers at all?
>
>
> "After execution of the final assignment to ByteVal, what will be the
> numeric value of X?
>
> void main()
> {
> unsigned char X=7;
> X <<= 4;
> }
>
> A) 28
> B) 11
> C) 112
> D) 56
> "

btw. I know that answer is 112, but I dont really understand the way how
to do such operations using pen and paper. I just forgot how to do
binary shift by hand. And thats what im asking about. So please dont
bitch about "homework" (in summer?!) or other bullshit.

Thank you

Stuart Golodetz
Guest
Posts: n/a

 08-02-2010
BozonHE wrote:
> In article <i364qk$cc0$(E-Mail Removed)>, (E-Mail Removed) says...
>> BozonHE wrote:
>>> Hello. I have following question, can someone explain to me, how I can
>>> shift left some value using only pen and paper? Or is there some clever
>>> way without playing with binary numbers at all?
>>>
>>>
>>> "After execution of the final assignment to ByteVal, what will be the
>>> numeric value of X?
>>>
>>> void main()
>>> {
>>> unsigned char X=7;
>>> X <<= 4;
>>> }
>>>
>>> A) 28
>>> B) 11
>>> C) 112
>>> D) 56
>>> "

>> This reminds me of the old joke: "There are 10 types of people - those
>> who understand binary and those who don't." That being said, here are
>> some base-neutral hints.
>>
>> A number a_n ... a_1 a_0 in base b actually means:
>>
>> \sum_{i=0}^n a_i b^i
>>
>> Thus the decimal number 234 means:
>>
>> 2*(10^2) + 3*(10^1) + 4*(10^0)
>>
>> Shifting a_n ... a_1 a_0 left by 1 yields:
>>
>> a_n ... a_1 a_0 0
>>
>> Or (if you prefer), a'_{n+1} a'_n ... a'_1 a'_0, where:
>>
>> a'_{i+1} = a_i (for i >= 0)
>> a'_0 = 0
>>
>> Thus, shifting 234 left by 1 in decimal yields:
>>
>> 2*(10^3) + 3*(10^2) + 4*(10^1) + 0*(10^0) = 2340
>>
>> This is 10 times the original number. I wonder what would happen if you
>> did the same exercise in binary...?
>>

> Can you show me example how to shift left int 7 by four using this
> technique? Because I have problems with that.
>
> Thank you.
>
> ps. I'm NOT asking about answer for any "homwework" (in summer WTF?!).
> I just forgot how to do such operations using pen and paper.

7 (base 10) = 4+2+1 (base 10) = 111 (base 2)

Shift left 4:

1110000 (base 2) = 64 + 32 + 16 (base 10) = 112 (base 10)

And don't grouch -- it's undignified I explained everything you
needed to know (besides just giving you the answer on a plate) in my
original post. It's the "give a man a fishing rod" strategy.

Stu

Öö Tiib
Guest
Posts: n/a

 08-02-2010
On 2 aug, 20:53, BozonHE <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed) >,
> (E-Mail Removed) says...
>
>
>
> > Hello. I have following question, can someone explain to me, how I can
> > shift left some value using only pen and paper? Or is there some clever
> > way without playing with binary numbers at all?

>
> > "After execution of the final assignment to ByteVal, what will be the
> > numeric value of X?

>
> > void main()
> > {
> > * unsigned char X=7;
> > * X <<= 4;
> > }

>
> > * *A) * * *28
> > * *B) * * *11
> > * *C) * * *112
> > * *D) * * *56
> > "

>
> btw. I know that answer is 112, but I dont really understand the way how
> to do such operations using pen and paper.

Pencil and paper? You multiply seven with ten and get seventy. Then
you multiply seven with six and get forty two. Then you add seventy
and forty two and get hundred twelve.

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post deepak21 Software 0 05-06-2012 09:01 AM pc C Programming 2 06-08-2011 06:58 PM Sanny Java 38 04-29-2011 10:02 PM Santosh Nayak C Programming 16 11-30-2006 05:10 PM Wenjie C++ 3 07-11-2003 08:22 PM

Advertisments