473,412 Members | 3,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

7 Hrs Left To Die ! Please Help

a program that repeatedly request an integer from the user and displays the integer as a binary number. It should terminate when the value 9999 is entered. A typical run might look like:
Enter integer: 16
00000000000000000000000000010000
Enter integer: -1
11111111111111111111111111111111
Enter integer: 9999
Try various values including negative and check that they are correct – the storage of signed numbers in binary was discussed in the level 1 module Computer Architecture.
You will need to use one of the shift operators (<< or >>) and the bitwise AND operator & (not &&). The basic idea is to AND a mask with the number. To give you an idea of the algorithm, suppose integers are 8 bits long rather than 32 bits and the variable data contains the number and the variable mask the mask.
Number 01110010
Mask 10000000
AND'ed = 10000000

If the result of AND'ing data with mask is non zero print a one else print a 0. Now shift the mask one bit right (>>) and repeat the AND.
number 01110010
mask 01000000
AND'ed = 01000000

Continue until the mask has been shifted eight bits right

ITS IN ANSI C . AND MASK IS MUST.
I HAVE DONE SO FAR THIS BUT CANT FIGURE OUT WHERE AND HOW TO ADD MASK.

Expand|Select|Wrap|Line Numbers
  1.  
  2. main()
  3. {
  4. int i,n;
  5. for(;;)
  6. {
  7. printf("\nEnter the number\n");//number to convert
  8. scanf("%d",&n);
  9. if ( n==9999) //condition check
  10. return;
  11. else
  12. {
  13. for(i=0;i<32;i++)
  14. {
  15. printf("%d",(n<<i & 1<<31 )?1:0); //converting to binary
  16. }// for ends
  17. }//else ends
  18. }//for ends
  19. }//main ends
  20.  
  21.  
  22.  
PLEASE HELP ME ASAP AS ONLY 7 HRS LEFT TO SUBMIT THIS . I REALLY NEED THE GRADE OF THIS.HELP
Oct 20 '06 #1
1 1671
Banfa
9,065 Expert Mod 8TB
What are you talking about, apart from the fact that

main()

should be declared

int main(int argc, char **argp)

for ANSI complience and of course since main returns int you should return a value

return 0;

is normal

you have a working program. The mask is incorperated into the printf statement, take a little time to understand how it is working.
Oct 20 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Techy | last post by:
I have used thecode which is below to get x characters on to display <%= LEFT(rsName.Fields.Item("columnname").Value,50)%> It works fine but when I use this same code to get x characters plus...
6
by: Allan | last post by:
Please help, below is my problem. Let's say I have 2 tables, a Products table and a Colors table that go as follow: Table Products prodID Name 1 shirt 2 tshirt
3
by: Allan | last post by:
Please help, below is my problem. Let's say I have 2 tables, a Products table and a Colors table that go as follow: Table Products prodID Name 1 shirt 2 tshirt
0
by: jonipony | last post by:
HELP: Float Left box is drifting to the right in ie! -------------------------- I need som HELP with my CSS coding! On the following web page my design falls apart at screen size 800 x 600...
9
by: sql guy123 | last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right() function. I need to use MS SQL for this project but I am not familiar with it. I have read a few books, but can not figure out...
0
by: yeahuh | last post by:
Quick and dirty version. Godaddy server using MySQL 4.0.24 I’m trying a left join to obtain id’s in table A(cars) that are NOT in car_id in table B(newspaper): *This is a cut down version...
2
by: rudicheow | last post by:
SHORT VERSION ============= I have a bunch of identical fixed-size single-celled tables that rest against each other horizontally thanks to "float:left". These tables are dynamically generated...
1
by: teneesh | last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
3
omerbutt
by: omerbutt | last post by:
hi , i am making a post notices section where i have to show the notices that are still valid, at the time of posting the notice i save the time stamp and date in different columns now i have to...
3
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.