UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How can you convert hexadecimal to binary without using arrays in C program?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Advance Excel And VBA Training

The moment a (C) program is loaded into a computer’s memory by the OS’s loader (in laymen terms - started) two concepts apply to the entity that we call data: storage representation On a separate note - as far as a computer is concerned everything it acts is a number: even what we call...
read more
The moment a (C) program is loaded into a computer’s memory by the OS’s loader (in laymen terms - started) two concepts apply to the entity that we call data: storage representation On a separate note - as far as a computer is concerned everything it acts is a number: even what we call code eventually becomes a carefully sequenced set of instructions each of which is still a number. As such, when a number comes to life it is stored in a format that can be acted on or manipulated by a given processor. When a human being wants to look at a number then the number’s representation becomes relevant: there is normally a one-to-many relationship between the storage and the representation since a number in an internal format can be rendered in various numerical basis, for example. A number in an internal, traditionally - binary, format is usually rendered in base sixteen in a textual form - as a sequence of characters each of which belongs to the base sixteen alphabet of 0 - 9 and A - F. If you have access to the variable of an integral binary type, such as int or long, for example, you can render that variable in a binary format directly. Assume that bits is a variable of the unsigned long type whose contents are to be rendered in a binary format on a 64 -bit machine: int i; char bd; unsigned long mask = 1UL << 63; for ( i = 0; i < 64; i++ ) { bd=bits & mask ? '1' : '0'; printf( "%c", bd ); mask>>= 1; } If you want to convert a base sixteen representation of a number to a binary representation then it can be done a multitude of ways. For example, convert the contents of the base sixteen string into an integral binary format via strtol() family of functions and then use the code above to render it visually in base two. If you are absolutely sure that the number rendered in base sixteen as string will fit into an int sized variable integer then: sscanf( string, "%x", &integer ); Adjust the sizes accordingly. If you want to convert a base sixteen character into a base two representation as an academic exercise then one way to do that is to: construct a base sixteen alphabet yourself in b16alph variable as follows: char b16alph[] = { '0', '1', '2', ..., 'F' }; scan the base sixteen string an a left-to-right fashion for each input base sixteen character hexch: find the location of hexch inside b16alph, say it's hexndx the contents of hexndx will be equal to the base ten internal representation of hexch render the contents of hexndx into base two representation as shown above (showing only a nibble, four rightmost bits, at a time: by shifting the mask leftward only 3 times (mask = 1 << 3)) read less
Comments

Home Tutor

/* C Program to convert decimal to binary without using array */ #include int main(){  int n, i, j, bin_rev=0,bin=0;  printf("Enter a number to convert : ");  scanf("%d",&n); /*****************************/  i=1;  while(n){  bin_rev=bin_rev+(n%2)*i;  i=i*10;  n=n/2;  }    i=1;  while(bin_rev){  bin=bin+(bin_rev%10)*i;  i=i*10;  bin_rev=bin_rev/10;  }  /*****************************/ printf("nBinary...
read more
/* C Program to convert decimal to binary without using array */ #include int main(){  int n, i, j, bin_rev=0,bin=0;  printf("Enter a number to convert : ");  scanf("%d",&n); /*****************************/  i=1;  while(n){  bin_rev=bin_rev+(n%2)*i;  i=i*10;  n=n/2;  }    i=1;  while(bin_rev){  bin=bin+(bin_rev%10)*i;  i=i*10;  bin_rev=bin_rev/10;  }  /*****************************/ printf("nBinary is %d",bin);    getch();  return 0; } read less
Comments

Related Questions

Why we use 'include stdio.h'?
The header file which is added to the program that one has written is basically what 'include stdio.h.' means. Stdio.h is known to contain the input and output operations like "printf" or "scanf" etc....
Jina
What is a calling function in C?
A calling function is a way to execute a block of code that's defined elsewhere in your program. It's like asking a specialized worker to perform a specific task within your main project. It promotes code organization, reusability, and modularity.
Deepika
0 0
6
What is the difference between compile time error and run time error?
Compile error is the error when you check for syntax error while run time error comes when you do execution of the program.
Varada
0 0
6
Is C programming necessary to learn to become a software engineer?
C language is starting language for programming, if you will understand the concept of C language then it would be very easy to learn all programming language because somehow concepts are similar
Ujwalajagdale
0 0
7
Who is the inventor of C programming?
Dennis Ritchie is inventor of C programming language.
Shreya
0 0
7

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Programming Practice Technique
Any Programming Language required an Algorithm. Algorithm - It is the finite set of instructions in which each and every instruction has the meaning, instructions are not ambiguous and all the instructions...

Dynamic Memory Allocation in C using malloc()
#include <stdio.h>#include <conio.h>//#include <malloc.h> OR#include <stdlib.h>void main(){ int *ptr, i, n, sum = 0; printf("how many elements ? "); scanf("%d", &n);...

C Language
To get help in C window (for keywords, functions) press Alt +F1.To delete a single line , use the shortcut key CTRL +Y.If you got error about the path when you execute a C pgm, check the Options menu =>Directories.
T

Thilagam S.

0 0
0

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

Storage classes in c
Storage classes determine the scope and life time of a variable. Scope is defined as the region over which the defined variable is accessible. Lifetime is the time during which the value of a variable...

Recommended Articles

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more