Search This Blog

Showing posts with label hexadecimal. Show all posts
Showing posts with label hexadecimal. Show all posts

C Program to Convert Between Hexadecimal, Octal, Binary and Decimal Numbers

This program deals with four number systems. They are:

  • Decimal (base 10)
  • Binary (base 2)
  • Octal (base 8)
  • Hexadecimal (base 16)
Here i post a  program for following operations:
  • Decimal to binary conversion
  • Decimal to Octal conversion
  • Decimal to Hexadecimal conversion
  • Binary to Decimal conversion
  • Binary to Octal conversion
  • Binary to Hexadecimal conversion
  • Octal to Decimal conversion
  • Octal to Binary conversion
  • Octal to Hexadecimal conversion
  • Hexadecimal to Decimal conversion
  • Hexadecimal to Binary conversion
  • Hexadecimal to Octal conversion
The following program lets you convert between the four number systems; decimal, binary, octal and hexadecimal number systems.

Program to Convert Hexadecimal to Decimal - Hexadecimal Conversion Program

Hexadecimal number system is base 16 number system in which the digits used are 0 to 9 and A to F. Here is a c program to convert hexadecimal number to decimal number system.

Program to Convert Decimal Number to Hexadecimal Number

This program is to convert a number in decimal number system (base 10) to a hexadecimal number (base 16). I have wrote a function reversestring to reverse a string. You may use strrev function instead if available. The program is as follows:

C Program Using 8086 Interrupts to Restrict Mouse Pointer Into a Circle of Given Center and Radius

C Program Using 8086 Interrupts to Restrict Mouse Pointer Into a Circle of Given Center and Radius. The mouse ponter will be restricted to a circle of user specified center and radius using the interrupt 33 of 8086 in c complier. I have tested this program in Turbo C compiler.
How to restrict mouse cursor or pointer within a user specified circle Using 8086 INT33 service interrupts arrow mice radius centre Turbo c program Turbo C++ code source code without thread screen rectangle
Mouse pointer restricted into a circle in Turbo C


#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>

void main()
{
int x,y,tx,ty,r;
union REGS inreg, outreg;
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
clrscr();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode,"C:\\TC\\BGI\\" );
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
setcolor(getmaxcolor());
printf("\nEnter the center of circle. x and y");
scanf("%d%d",&x,&y);
printf("\nEnter the radius of circle");
scanf("%d",&r);
clrscr();
circle(x,y,r);
inreg.x.ax=0x1;
int86(0x33,&inreg,&outreg);
inreg.x.ax=0x7;
inreg.x.cx=x-r;
inreg.x.dx=x+r;
int86(0x33,&inreg,&outreg);
inreg.x.ax=0x8;
inreg.x.cx=y-r;
inreg.x.dx=y+r;
int86(0x33,&inreg,&outreg);
do
{
inreg.x.ax=0x3;
int86(0x33,&inreg,&outreg);
tx=outreg.x.cx;
ty=outreg.x.dx;
if((tx-x)*(tx-x)+(ty-y)*(ty-y)>r*r)
{
if(tx<=x)
{
if(ty<y)
do{tx++; ty++;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
else
do{tx++; ty--;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
}
else
{
if(ty<=y)
do{tx--; ty++;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
else
do{tx--; ty--;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
}
inreg.x.ax=0x4;
inreg.x.cx=tx;
inreg.x.dx=ty;
int86(0x33,&inreg,&outreg);
}
}while(1);
}