LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-01-2004, 08:15 PM   #1
linuxanswer
Member
 
Registered: Oct 2003
Distribution: woodY 3.0 stable
Posts: 61

Rep: Reputation: 15
shift operator


anyone can explaine me the meaning of
(var & 0x000000ff);
(var & 0x0000ff00) >> 8;
(var & 0x00ff0000) >> 16;
(var & 0xff000000) >> 24;
why use this ? and pratically , what they do ?
tnx in advance
 
Old 05-01-2004, 08:33 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
First one takes the first 8 bits of the variable var.
Second one takes the second 8 bits of the variable var (drops other to zero) and moves those 8 bits to te begining of the word.
Third and fourth does the same, but for third and fourth 8 bits.

eg. if you have a 32bit number (in bit representation)
10111110 01111001 11100001 10110101
The first command returns,10110101.

Second 11100001. This is done by bitwise anding
00000000 00000000 11111111 00000000 (the 0x0000ff00) and
10111110 01111001 11100001 10110101
leaving a number
00000000 00000000 11100001 00000000.
Shifting this 8 bits to the right leaves (begining zeros omited): 11100001.

Similary the third is 01111001 and fourth is 10111110.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I shift my screen over? bad_andy Mandriva 6 10-24-2004 11:52 AM
Shift the Desktop... LordGoddard Linux - Software 15 04-28-2004 04:26 PM
~ operator linuxanswer Programming 7 04-08-2004 05:56 PM
Shift operator Xiangbuilder Programming 4 10-04-2003 03:07 PM
MS strategy shift awdoyle General 13 12-11-2002 01:36 PM


All times are GMT -5. The time now is 11:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration