| | |
help with codes
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 13
Reputation:
Solved Threads: 0
how do you convert to binary.
i have to write a program that will prompt the user to enter an unlimited(user defined) number positive intergers, the program will convert each positive interger(base 10 value) into its equivalent binary representation and displat each conversation. to exit the program, the user is to ente a negative interger.
the largest enterger value to be used is 15, i also have to create an array of SIZE 4(all array position are to begin with the value '0' in each position).
prompt the user to enter an interger between 0 and 15;
convert the interger to its equivalent binary value;
display the new binary value.
can someone please help me with this and you show me an example.
i have to write a program that will prompt the user to enter an unlimited(user defined) number positive intergers, the program will convert each positive interger(base 10 value) into its equivalent binary representation and displat each conversation. to exit the program, the user is to ente a negative interger.
the largest enterger value to be used is 15, i also have to create an array of SIZE 4(all array position are to begin with the value '0' in each position).
prompt the user to enter an interger between 0 and 15;
convert the interger to its equivalent binary value;
display the new binary value.
can someone please help me with this and you show me an example.
the program displays the binary code for integers up to 32,768 in
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> void main( int argc, char *argv[] ) { int arg1, x; if( argc == 1 ) { puts( "BINARY num = displays num in binary form." ); exit( 1 ); } arg1 = atoi( argv[1] ); printf( "INTEGER: %i\n", arg1 ); printf( " HEX: %x\n", arg1 ); printf( " BINARY:" ); for( x = 15; x > 7; x-- ) printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 ); printf( " " ); for( x = 7; x > -1; x-- ) printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 ); puts( "" ); puts( " 16 bit:15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0" ); puts( " 8 bit: 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0" ); puts( " Hex: |----4---| |----3---| |----2---| |----1---|" ); puts( " Sum: 3 1 " ); puts( " 2 6 8 4 2 1 " ); puts( " 7 3 1 0 0 0 5 2 1 " ); puts( " 6 8 9 9 4 2 1 5 2 6 3 1 " ); puts( " 8 4 2 6 8 4 2 6 8 4 2 6 8 4 2 1" ); exit( 0 ); }
Last edited by alc6379; Nov 19th, 2004 at 11:43 am.
Real Eyes Realize Real Lies
My Resume
My Resume
•
•
•
•
Originally Posted by meabed
the program displays the binary code for integers up to 32,768 in
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> void main( int argc, char *argv[] ) { int arg1, x; if( argc == 1 ) { puts( "BINARY num = displays num in binary form." ); exit( 1 ); } arg1 = atoi( argv[1] ); printf( "INTEGER: %i\n", arg1 ); printf( " HEX: %x\n", arg1 ); printf( " BINARY:" ); for( x = 15; x > 7; x-- ) printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 ); printf( " " ); for( x = 7; x > -1; x-- ) printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 ); puts( "" ); puts( " 16 bit:15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0" ); puts( " 8 bit: 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0" ); puts( " Hex: |----4---| |----3---| |----2---| |----1---|" ); puts( " Sum: 3 1 " ); puts( " 2 6 8 4 2 1 " ); puts( " 7 3 1 0 0 0 5 2 1 " ); puts( " 6 8 9 9 4 2 1 5 2 6 3 1 " ); puts( " 8 4 2 6 8 4 2 6 8 4 2 6 8 4 2 1" ); exit( 0 ); }
New members chased away this month: 3
![]() |
Similar Threads
- Codes for "Find" and for "Tip of the day" (Visual Basic 4 / 5 / 6)
- Checking source codes of image, audio and video files (Site Layout and Usability)
- Checking source codes of image, audio and video files (Graphics and Multimedia)
- How to create multiple toggle field codes in Word. (MS Access and FileMaker Pro)
- beginner"problem in arrays help me in codes" (C)
- Color disply codes for C++? (C++)
- Can't view source codes (Web Browsers)
Other Threads in the C Forum
- Previous Thread: Mouse-over (rollover) effect in a Windows GUI program
- Next Thread: beginner"problem in arrays help me in codes"
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






