C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 24th, 2006, 02:29 AM
rajkarki rajkarki is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 rajkarki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 6 sec
Reputation Power: 0
C code to rotate a bit in a given number

1)how will u rotate a bit in a given number ?i need the C code.
2)how wil concatenate two strings without using library function in C.

Reply With Quote
  #2  
Old March 24th, 2006, 04:41 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Quote:
Originally Posted by rajkarki
1)how will u rotate a bit in a given number ?i need the C code.

C Code:
Original - C Code
  1. #include <stdio.h>
  2. #define ROT_LEFT 0x00
  3. #define ROT_RIGHT !ROT_LEFT
  4.  
  5. int rotate(int invalue, int places, int direction)
  6. {
  7.     int outvalue;
  8.    
  9.     /*  Rotating left or right?   */
  10.     if(direction == ROT_LEFT)
  11.     {
  12.         /*  First a normal shift  */
  13.         outvalue = invalue << (places % (8 * sizeof(int)));
  14.         outvalue |= invalue >> ((8 * sizeof(int)) - places % (8 * sizeof(int)));
  15.     }
  16.     else
  17.     {
  18.         /*  First a normal shift  */
  19.         outvalue = invalue >> (places % (8 * sizeof(int)));
  20.         /*  Then place the part that's shifted off the screen at the end  */
  21.         outvalue |= invalue << ((8 * sizeof(int)) - places % (8 * sizeof(int)));
  22.     }
  23.     return outvalue;
  24. }
  25.  
  26. int main()
  27. {
  28.     /*  Declarations  */
  29.     int test;
  30.     test = 0x12345678;
  31.    
  32.     /*  Rotate    */
  33.     test = rotate(test, 4, ROT_LEFT);
  34.    
  35.     /*  Output    */
  36.     printf("%x\n", test);
  37.    
  38.     /*  Return succes */
  39.     return 0;
  40. }


Quote:
Originally Posted by rajkarki
2)how wil concatenate two strings without using library function in C.

C Code:
Original - C Code
  1. #include <stdio.h>
  2. #define STR_1_SIZE 10
  3. #define STR_2_SIZE 26
  4.  
  5. int main()
  6. {
  7.     /*      Delarations     */
  8.     char str1[STR_1_SIZE + 1] = "1234567890\0";
  9.     char str2[STR_2_SIZE + 1] = "abcdefghijklmnopqrstuvwxyz\0";
  10.     char str_result[STR_1_SIZE + STR_2_SIZE + 1];
  11.     int i;
  12.  
  13.     /*      Concatenate     */
  14.     for(i = 0; i < (STR_1_SIZE + STR_2_SIZE); ++i)
  15.         if(i < STR_1_SIZE)
  16.             str_result[i] = str1[i];
  17.         else
  18.             str_result[i] = str2[i - STR_1_SIZE];
  19.     str_result[i] = '\0';
  20.  
  21.     /*      Output  */
  22.     printf("%s %s %s\n", str1, str2, str_result);
  23.  
  24.     /*      Return succes   */
  25.     return 0;
  26. }
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C code to rotate a bit in a given number


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT