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

What is the benefit of using an enum rather than a #define constant?
The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability,...
Basundhara
0 0
7
Can anybody provide me error free coding for graphic program in C??? Animated Smiley program Rotating Fan progran Sunrise program
#include graphics.h #include conio.h #include stdlib.h #include dos.h main() { int gd = DETECT, gm,area,temp1,temp2,left =25,top=75; void *p; initgraph(&gd,&gm,”C:\TC\BGI”); setcolor(YELLOW); circle(50,100,25); setfillstyle(SOLID_FILL,YELLOW); floodfill(50,100,YELLOW); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); fillellipse(44,85,2,6); fillellipse(56,85,2,6); ellipse(50,100.205,335,20,9); ellipse(50,100.205,335,20,10); ellipse(50,100.205,335,20,11); area...
Gayu
0 0
8
Is c language easy to learn?
The ease of learning C language depends on your prior programming experience and familiarity with certain concepts. For beginners, C can be challenging due to its syntax and manual memory management. However,...
Vikash
0 0
6
Which language is best, C, C++, Python or Java?
If you want to learn any languages C#, Java, ect. then must to learn C, C++ language as these are base or language to be strong in language skills. C++ is improved version of C language. C#, Java, J# and etc. which are improved version of C++.
Sribaghya
0 0
6

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

Ask a Question

Related Lessons


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

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

Datatypes in C Language
Data types in C Language Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that...

C Program-Temperature [conversion from farenheit to degree celsius]
//WAP to convert temperture from farenheit into degree celsius //Header files#include<stdio.h>#include<conio.h> //Main functrion void main(){ //Variable declaration of type float float...
S

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