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

How can I learn C easily and rapidly?
You can learn C by three ways 1. Practise 10 programs daily for 10 days. 2. Understand the programming concept before going to make an attempt 3. Try to do some simple projects on your own will improve your skills rapidly.
Umamahesh
0 0
5
What is the meaning of \n and \t in C language?
is used for new line and \t is used to give 3-space (1 tab space) in between the words
Soumya
0 0
5
How do I get 6 power 13 in c language?
By using pow() function #include <math.h>#include <stdio.h>int main() { double base = 6.0; double exp = 13.0; double result = pow(base, exp); printf("%.1lf^%.1lf = %.2lf", base, exp, result); return 0;}
Tanush
0 0
5
What is the concatenation operator?
In many programming languages, string concatenation is a binary infix operator. The + (plus) operator is often overloaded to denote concatenation for string arguments: "Hello, " + "World" has the value...
R.s.praveen
If one leaves a lot of space in a C language code, will it require more space in a hard disk and RAM?
Head files tells system, how to deal with different functions with program such as printf(), scanf() , getche() etc. so you must have reference to it.
Abhishek
0 0
5

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

Ask a Question

Related Lessons

Variables
Variables in C Language:A variable is a name that may be used to store a data value. Unlike constant, variables are changeable, we can change value of a variable during execution of a program. A programmer...

C Program Sample Application
//Standard Library Functions(Header Files used) #include<stdio.h> #include <conio.h> //Main method int main() { // function for clearing screen clrscr(); // function to print the output...

Programing Languages Learning Tricks
You want to learn that new language or library or framework as soon as possible, right? That’s understandable. Fortunately, there are a handful of tips that can help you to better retain all of that...

Harshal G.

0 0
0

Do You Know How Is Size Of Structure Defined?
Size of the structure is defined based on multiplies of bigger data type member in the structure. Example: If a structure contains integer, char, short data type, then size of the Structure will be multiples...

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Recommended Articles

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 >

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 >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

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