bitwise shift opratore....

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2009
Posts: 25
Reputation: nitu_thakkar has a little shameless behaviour in the past 
Solved Threads: 1
nitu_thakkar's Avatar
nitu_thakkar nitu_thakkar is offline Offline
Light Poster

bitwise shift opratore....

 
0
  #1
Jan 16th, 2009
suppose i want to do shift left opeartion on

x=1010

y=x<<1

it will shift left the value

& make x=0100 but how can i store that

shifted value... in other variable...?

please help me to solve this query
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,862
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: bitwise shift opratore....

 
0
  #2
Jan 16th, 2009
Originally Posted by nitu_thakkar View Post
y=x<<1

it will shift left the value

& make x=0100 but how can i store that shifted value... in other variable...?
Uh... you say: y = x << 1 right? So what do you think 'y' is? Holy cow it's another variable! So you already stored in another variable. problem solved kthxbye!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 44
Reputation: zalezog is an unknown quantity at this point 
Solved Threads: 11
zalezog zalezog is offline Offline
Light Poster

Re: bitwise shift opratore....

 
0
  #3
Jan 16th, 2009
Originally Posted by nitu_thakkar View Post
suppose i want to do shift left operation on

x=1010

y=x<<1

it will shift left the value

& make x=0100 but how can i store that

shifted value... in other variable...?

please help me to solve this query
1. l x=10;
and left shifting the bits once does not give you 0100
but 10100(ie.20)

2.If you want the output to be converted into a binary format
you can try out something like this:

A)If the input_number is greater than 0,
input_number%2 and store the remainder in an array('char'of sufficient size)

B)Divide the input_number by 2.Goto Step A

Place a delimitter such as a'\0' at the end.

The only disadvantage being the binary number so obtained is
reversed
Use a reverse counting loop to get the binary content.
Last edited by zalezog; Jan 16th, 2009 at 7:33 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 10
Reputation: iyercb is an unknown quantity at this point 
Solved Threads: 1
iyercb iyercb is offline Offline
Newbie Poster

Re: bitwise shift opratore....

 
0
  #4
Jan 16th, 2009
Originally Posted by nitu_thakkar View Post
suppose i want to do shift left opeartion on

x=1010

y=x<<1

it will shift left the value

& make x=0100 but how can i store that

shifted value... in other variable...?

please help me to solve this query
Minimum data in most computers is a byte hence I think you mean
x=00001010 which is decimal 10 and when you say y=x<<1 the value of y is 00010100 which is decimal 20. x does not change its value when you say y=x<<1, so your original statement is doing precisely what you want.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 25
Reputation: nitu_thakkar has a little shameless behaviour in the past 
Solved Threads: 1
nitu_thakkar's Avatar
nitu_thakkar nitu_thakkar is offline Offline
Light Poster

Re: bitwise shift opratore....

 
0
  #5
Jan 18th, 2009
sorry for mistake but my actually question is,

i want to make one program binary no.s multiplication

(using register method)

i have to follow some rules,

no1=1010

no2=0101

Rules are:

store no1 in 8-bit register (like this way)

no1=10100000

then have to perform shift left opration on it. (shift only one bit)

so,
no1=01000000

if shifted no. is 1 then add no2 with no1

like

no1=01000000
+
no2=00000101 (have to store no2 like this way)

no1=01000101

then agin do shift left operation ...

if shifted value is 1 than add no2 if not then add 0

repeat this process four time

i wann make program for this purpose

so how can i get that shifted bit value (if it 1 or 0)

becaues basis on this opeation is perfomed
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 90
Reputation: ajay.krish123 is an unknown quantity at this point 
Solved Threads: 8
ajay.krish123 ajay.krish123 is offline Offline
Junior Poster in Training

Re: bitwise shift opratore....

 
0
  #6
Jan 18th, 2009
there are many registers available in the compiler into which you can store directly your numbers.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: bitwise shift opratore....

 
0
  #7
Jan 18th, 2009
@nitu: Do you know how to use any other bit-operators?

@ajay: I believe you mean, computer. Regs are for brief usage, not storage.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC