Convert hexadecimal to octal number

Here given code implementation process.

//C Program
//Convert hexadecimal to octal number
#include <stdio.h>

int power(int number,int size)
{
  if(size==0)
  {
    return 1;
  }
  if(number == 0)
  {
    return 0;
  }
  else
  {
    int result=number;

    for (int i = 2; i <= size; ++i)
    {
      result=result*number;
    }
    return result;
  }
}
//Convert decimal number into octal
int octal(int number)
{
  int result = 0;
  int multiplier=1,remainder = 0;
  while(number!=0)
  {
   
    remainder=number%8;

   
    result=(remainder*multiplier)+result;
     
    multiplier*=10;
    number/=8;
  }
  return result;
}
void hexa_octal(char *hexa)
{
  
  int decimal=0;

  int digits=0;
  
  int flag = 0;

  int i = 0;

  if(hexa[0]=='-')
  {
    flag = 1;
  }

  for (i = flag; hexa[i]!='\0'; ++i)
  {
    digits++;
  }
  //First convert hexadecimal to decimal number
  for (i = flag; hexa[i]!='\0'; ++i,--digits)
  {
  
    if(hexa[i]>='0' && hexa[i]<='9')
    {
      //When hex digit, is a number
      decimal+= (hexa[i]-48) * power(16,digits-1);
    }
    else if(hexa[i]>='a' && hexa[i]<='f')
    {
      // When of hexadecimal digit is an lowercase letter
      decimal+= (hexa[i]-87) * power(16,digits-1);
    }
    else if(hexa[i]>='A' && hexa[i]<='F')
    {
      // When of hexadecimal digit is an uppercase letter
      decimal+= (hexa[i]-55) * power(16,digits-1);
    }
    else
    {
      //invalid hexa decimal
      return;
    } 
  }

  decimal=octal(decimal);
  
  if(flag==1)
  {
    decimal = -decimal;
  }
  printf("Hexa : %s  Octal : %d",hexa ,decimal);
  printf("\n");
}
int main()
{
  hexa_octal("A1");
  hexa_octal("1A");
  hexa_octal("f6");
  hexa_octal("3E8");
  hexa_octal("-E8");
  return 0;
}

Output

Hexa : A1  Octal : 241
Hexa : 1A  Octal : 32
Hexa : f6  Octal : 366
Hexa : 3E8  Octal : 1750
Hexa : -E8  Octal : -350
/*
  Java Program
  Convert hexadecimal to octal number
*/
public class MyNumber
{
	public int power(int number, int size)
	{
		if (size == 0)
		{
			return 1;
		}
		if (number == 0)
		{
			return 0;
		}
		else
		{
			int result = number;
			for (int i = 2; i <= size; ++i)
			{
				result = result *number;
			}
			return result;
		}
	}
	//Convert decimal number into octal
	public int octal(int number)
	{
		int result = 0;
		int multiplier = 1, remainder = 0;
		while (number != 0)
		{
			remainder = number % 8;
			result = (remainder *multiplier) + result;
			multiplier *= 10;
			number /= 8;
		}
		return result;
	}
	public void hexa_octal(String hexa)
	{
		if (hexa.length() <= 0)
		{
			return;
		}
		int decimal = 0;
		int digits = 0;
		int flag = 0;
		int i = 0;
		if (hexa.charAt(i) == '-')
		{
			flag = 1;
		}
		for (i = flag; i < hexa.length(); ++i)
		{
			digits++;
		}
		//First convert hexadecimal to decimal number
		for (i = flag; i < hexa.length(); ++i, --digits)
		{
			if (hexa.charAt(i) >= '0' && hexa.charAt(i) <= '9')
			{
				//When hex digit, is a number
				decimal += (hexa.charAt(i) - 48) *power(16, digits - 1);
			}
			else if (hexa.charAt(i) >= 'a' && hexa.charAt(i) <= 'f')
			{
				// When of hexadecimal digit is an lowercase letter
				decimal += (hexa.charAt(i) - 87) *power(16, digits - 1);
			}
			else if (hexa.charAt(i) >= 'A' && hexa.charAt(i) <= 'F')
			{
				// When of hexadecimal digit is an uppercase letter
				decimal += (hexa.charAt(i) - 55) *power(16, digits - 1);
			}
			else
			{
				// Invalid hexa decimal
				return;
			}
		}
		digits = octal(decimal);
		if (flag == 1)
		{
			digits = -digits;
		}
		System.out.print("Hexa : " + hexa + " Octal : " + digits);
		System.out.print("\n");
	}
	public static void main(String[] args)
	{
		MyNumber obj = new MyNumber();
		//Test Case
		obj.hexa_octal("A1");
		obj.hexa_octal("1A");
		obj.hexa_octal("f6");
		obj.hexa_octal("3E8");
		obj.hexa_octal("-E8");
	}
}

Output

Hexa : A1  Octal : 241
Hexa : 1A  Octal : 32
Hexa : f6  Octal : 366
Hexa : 3E8  Octal : 1750
Hexa : -E8  Octal : -350
/*
  C++ Program
  Convert hexadecimal to octal number
*/
#include<iostream>

using namespace std;
class MyNumber
{
	public: int power(int number, int size)
	{
		if (size == 0)
		{
			return 1;
		}
		if (number == 0)
		{
			return 0;
		}
		else
		{
			int result = number;
			for (int i = 2; i <= size; ++i)
			{
				result = result *number;
			}
			return result;
		}
	}
	//Convert decimal number into octal
	int octal(int number)
	{
		int result = 0;
		int multiplier = 1, remainder = 0;
		while (number != 0)
		{
			remainder = number % 8;
			result = (remainder *multiplier) + result;
			multiplier *= 10;
			number /= 8;
		}
		return result;
	}
	void hexa_octal(string hexa)
	{
		if (hexa.size() <= 0)
		{
			return;
		}
		int decimal = 0;
		int digits = 0;
		int flag = 0;
		int i = 0;
		if (hexa[i] == '-')
		{
			flag = 1;
		}
		for (i = flag; i < hexa.size(); ++i)
		{
			digits++;
		}
		//First convert hexadecimal to decimal number
		for (i = flag; i < hexa.size(); ++i, --digits)
		{
			if (hexa[i] >= '0' && hexa[i] <= '9')
			{
				//When hex digit, is a number
				decimal += (hexa[i] - 48) *this->power(16, digits - 1);
			}
			else if (hexa[i] >= 'a' && hexa[i] <= 'f')
			{
				// When of hexadecimal digit is an lowercase letter
				decimal += (hexa[i] - 87) *this->power(16, digits - 1);
			}
			else if (hexa[i] >= 'A' && hexa[i] <= 'F')
			{
				// When of hexadecimal digit is an uppercase letter
				decimal += (hexa[i] - 55) *this->power(16, digits - 1);
			}
			else
			{
				// Invalid hexa decimal
				return;
			}
		}
		digits = this->octal(decimal);
		if (flag == 1)
		{
			digits = -digits;
		}
		cout << "Hexa : " << hexa << " Octal : " << digits;
		cout << "\n";
	}
};
int main()
{
	MyNumber obj =  MyNumber();
	//Test Case
	obj.hexa_octal("A1");
	obj.hexa_octal("1A");
	obj.hexa_octal("f6");
	obj.hexa_octal("3E8");
	obj.hexa_octal("-E8");
	return 0;
}

Output

Hexa : A1 Octal : 241
Hexa : 1A Octal : 32
Hexa : f6 Octal : 366
Hexa : 3E8 Octal : 1750
Hexa : -E8 Octal : -350
/*
  C# Program
  Convert hexadecimal to octal number
*/
using System;
public class MyNumber
{
	public int power(int number, int size)
	{
		if (size == 0)
		{
			return 1;
		}
		if (number == 0)
		{
			return 0;
		}
		else
		{
			int result = number;
			for (int i = 2; i <= size; i++)
			{
				result = result * number;
			}
			return result;
		}
	}
	//Convert decimal number into octal
	public int octal(int number)
	{
		int result = 0;
		int multiplier = 1, reMainder = 0;
		while (number != 0)
		{
			reMainder = number % 8;
			result = (reMainder * multiplier) + result;
			multiplier *= 10;
			number /= 8;
		}
		return result;
	}
	public void hexa_octal(String hexa)
	{
		if (hexa.Length <= 0)
		{
			return;
		}
		int decimals = 0;
		int digits = 0;
		int flag = 0;
		int i = 0;
		if (hexa[i] == '-')
		{
			flag = 1;
		}
		for (i = flag; i < hexa.Length; i++)
		{
			digits++;
		}
		//First convert hexadecimal to decimal number
		for (i = flag; i < hexa.Length; i++, digits--)
		{
			if (hexa[i] >= '0' && hexa[i] <= '9')
			{
				//When hex digit, is a number
				decimals += (hexa[i] - 48) * power(16, digits - 1);
			}
			else if (hexa[i] >= 'a' && hexa[i] <= 'f')
			{
				// When of hexadecimal digit is an lowercase letter
				decimals += (hexa[i] - 87) * power(16, digits - 1);
			}
			else if (hexa[i] >= 'A' && hexa[i] <= 'F')
			{
				// When of hexadecimal digit is an uppercase letter
				decimals += (hexa[i] - 55) * power(16, digits - 1);
			}
			else
			{
				// Invalid hexa decimal
				return;
			}
		}
		digits = octal(decimals);
		if (flag == 1)
		{
			digits = -digits;
		}
		Console.Write("Hexa : " + hexa + " Octal : " + digits);
		Console.Write("\n");
	}
	public static void Main(String[] args)
	{
		MyNumber obj = new MyNumber();
		//Test Case
		obj.hexa_octal("A1");
		obj.hexa_octal("1A");
		obj.hexa_octal("f6");
		obj.hexa_octal("3E8");
		obj.hexa_octal("-E8");
	}
}

Output

Hexa : A1 Octal : 241
Hexa : 1A Octal : 32
Hexa : f6 Octal : 366
Hexa : 3E8 Octal : 1750
Hexa : -E8 Octal : -350
<?php
/*
  Php Program
  Convert hexadecimal to octal number
*/
class MyNumber
{
	public 	function power($number, $size)
	{
		if ($size == 0)
		{
			return 1;
		}
		if ($number == 0)
		{
			return 0;
		}
		else
		{
			$result = $number;
			for ($i = 2; $i <= $size; ++$i)
			{
				$result = $result *$number;
			}
			return $result;
		}
	}
	//Convert decimal number into octal
	public 	function octal($number)
	{
		$result = 0;
		$multiplier = 1;
		$remainder = 0;
		while ($number != 0)
		{
			$remainder = $number % 8;
			$result = ($remainder *$multiplier) + $result;
			$multiplier *= 10;
			$number = intval($number / 8);
		}
		return $result;
	}
	public 	function hexa_octal($hexa)
	{
		if (strlen($hexa) <= 0)
		{
			return;
		}
		$decimal = 0;
		$digits = 0;
		$flag = 0;
		$i = 0;
		if ($hexa[$i] == '-')
		{
			$flag = 1;
		}
		for ($i = $flag; $i < strlen($hexa); ++$i)
		{
			$digits++;
		}
		//First convert hexadecimal to decimal number
		for ($i = $flag; $i < strlen($hexa); ++$i, --$digits)
		{
			if (ord($hexa[$i]) >= ord('0') && ord($hexa[$i]) <= ord('9'))
			{
				//When hex digit, is a number
				$decimal += (ord($hexa[$i]) - 48) *$this->power(16, $digits - 1);
			}
			else if (ord($hexa[$i]) >= ord('a') && ord($hexa[$i]) <= ord('f'))
			{
				// When of hexadecimal digit is an lowercase letter
				$decimal += (ord($hexa[$i]) - 87) *$this->power(16, $digits - 1);
			}
			else if (ord($hexa[$i]) >= ord('A') && ord($hexa[$i]) <= ord('F'))
			{
				// When of hexadecimal digit is an uppercase letter
				$decimal += (ord($hexa[$i]) - 55) *$this->power(16, $digits - 1);
			}
			else
			{
				return;
			}
		}
		$digits = $this->octal($decimal);
		if ($flag == 1)
		{
			$digits = -$digits;
		}
		echo("Hexa : ". $hexa ." Octal : ". $digits);
		echo("\n");
	}
}

function main()
{
	$obj = new MyNumber();
	//Test Case
	$obj->hexa_octal("A1");
	$obj->hexa_octal("1A");
	$obj->hexa_octal("f6");
	$obj->hexa_octal("3E8");
	$obj->hexa_octal("-E8");
}
main();

Output

Hexa : A1 Octal : 241
Hexa : 1A Octal : 32
Hexa : f6 Octal : 366
Hexa : 3E8 Octal : 1750
Hexa : -E8 Octal : -350
/*
  Node Js Program
  Convert hexadecimal to octal number
*/
class MyNumber
{
	power(number, size)
	{
		if (size == 0)
		{
			return 1;
		}
		if (number == 0)
		{
			return 0;
		}
		else
		{
			var result = number;
			for (var i = 2; i <= size; ++i)
			{
				result = result *number;
			}
			return result;
		}
	}
	//Convert decimal number into octal
	octal(number)
	{
		var result = 0;
		var multiplier = 1;
		var remainder = 0;
		while (number != 0)
		{
			remainder = number % 8;
			result = (remainder *multiplier) + result;
			multiplier *= 10;
			number = parseInt(number / 8);
		}
		return result;
	}
	hexa_octal(hexa)
	{
		if (hexa.length <= 0)
		{
			return;
		}
		var decimal = 0;
		var digits = 0;
		var flag = 0;
		var i = 0;
		if (hexa[i] == '-')
		{
			flag = 1;
		}
		for (i = flag; i < hexa.length; ++i)
		{
			digits++;
		}
		//First convert hexadecimal to decimal number
		for (i = flag; i < hexa.length; ++i, --digits)
		{
			if ((hexa[i]).charCodeAt(0) >= ('0').charCodeAt(0) && (hexa[i]).charCodeAt(0) <= ('9').charCodeAt(0))
			{
				//When hex digit, is a number
				decimal += ((hexa[i]).charCodeAt(0) - 48) *this.power(16, digits - 1);
			}
			else if ((hexa[i]).charCodeAt(0) >= ('a').charCodeAt(0) && (hexa[i]).charCodeAt(0) <= ('f').charCodeAt(0))
			{
				// When of hexadecimal digit is an lowercase letter
				decimal += ((hexa[i]).charCodeAt(0) - 87) *this.power(16, digits - 1);
			}
			else if ((hexa[i]).charCodeAt(0) >= ('A').charCodeAt(0) && (hexa[i]).charCodeAt(0) <= ('F').charCodeAt(0))
			{
				// When of hexadecimal digit is an uppercase letter
				decimal += ((hexa[i]).charCodeAt(0) - 55) *this.power(16, digits - 1);
			}
			else
			{
				return;
			}
		}
		digits = this.octal(decimal);
		if (flag == 1)
		{
			digits = -digits;
		}
		process.stdout.write("Hexa : " + hexa + " Octal : " + digits);
		process.stdout.write("\n");
	}
}

function main(args)
{
	var obj = new MyNumber();
	//Test Case
	obj.hexa_octal("A1");
	obj.hexa_octal("1A");
	obj.hexa_octal("f6");
	obj.hexa_octal("3E8");
	obj.hexa_octal("-E8");
}
main();

Output

Hexa : A1 Octal : 241
Hexa : 1A Octal : 32
Hexa : f6 Octal : 366
Hexa : 3E8 Octal : 1750
Hexa : -E8 Octal : -350
#   Python 3 Program
#   Convert hexadecimal to octal number

class MyNumber :
	def power(self, number, size) :
		if (size == 0) :
			return 1
		
		if (number == 0) :
			return 0
		else :
			result = number
			i = 2
			while (i <= size) :
				result = result * number
				i += 1
			
			return result
		
	
	# Convert decimal number into octal
	def octal(self, number) :
		result = 0
		multiplier = 1
		remainder = 0
		while (number != 0) :
			remainder = number % 8
			result = (remainder * multiplier) + result
			multiplier *= 10
			number = int(number / 8)
		
		return result
	
	def hexa_octal(self, hexa) :
		if (len(hexa) <= 0) :
			return
		
		decimal = 0
		digits = 0
		flag = 0
		i = 0
		if (hexa[i] == '-') :
			flag = 1
		
		i = flag
		while (i < len(hexa)) :
			digits += 1
			i += 1
		
		# First convert hexadecimal to decimal number
		i = flag
		while (i < len(hexa)) :
			if (ord(hexa[i]) >= ord('0') and ord(hexa[i]) <= ord('9')) :
				# When hex digit, is a number
				decimal += (ord(hexa[i]) - 48) * self.power(16, digits - 1)
			elif (ord(hexa[i]) >= ord('a') and ord(hexa[i]) <= ord('f')) :
				#  When of hexadecimal digit is an lowercase letter
				decimal += (ord(hexa[i]) - 87) * self.power(16, digits - 1)
			elif (ord(hexa[i]) >= ord('A') and ord(hexa[i]) <= ord('F')) :
				#  When of hexadecimal digit is an uppercase letter
				decimal += (ord(hexa[i]) - 55) * self.power(16, digits - 1)
			else :
				return
			
			i += 1
			digits -= 1
		
		digits = self.octal(decimal)
		if (flag == 1) :
			digits = -digits
		
		print("Hexa : ", hexa ," Octal : ", digits, end = "")
		print("\n", end = "")
	

def main() :
	obj = MyNumber()
	# Test Case
	obj.hexa_octal("A1")
	obj.hexa_octal("1A")
	obj.hexa_octal("f6")
	obj.hexa_octal("3E8")
	obj.hexa_octal("-E8")


if __name__ == "__main__": main()

Output

Hexa :  A1  Octal :  241
Hexa :  1A  Octal :  32
Hexa :  f6  Octal :  366
Hexa :  3E8  Octal :  1750
Hexa :  -E8  Octal :  -350
#   Ruby Program
#   Convert hexadecimal to octal number

class MyNumber

	def power(number, size)
	
		if (size == 0)
		
			return 1
		end
		if (number == 0)
		
			return 0
		else
		
			result = number
			i = 2
			while (i <= size)
			
				result = result * number
				i += 1
			end
			return result
		end
	end
	# Convert decimal number into octal
	def octal(number)
	
		result = 0
		multiplier = 1
		remainder = 0
		while (number != 0)
		
			remainder = number % 8
			result = (remainder * multiplier) + result
			multiplier *= 10
			number /= 8
		end
		return result
	end
	def hexa_octal(hexa)
	
		if (hexa.length() <= 0)
		
			return
		end
		decimal = 0
		digits = 0
		flag = 0
		i = 0
		if (hexa[i] == '-')
		
			flag = 1
		end
		i = flag
		while (i < hexa.length())
		
			digits += 1
			i += 1
		end
		# First convert hexadecimal to decimal number
		i = flag
		while (i < hexa.length())
		
			if ((hexa[i]).ord >= ('0').ord && (hexa[i]).ord <= ('9').ord)
			
				# When hex digit, is a number
				decimal += ((hexa[i]).ord - 48) * self.power(16, digits - 1)
			elsif ((hexa[i]).ord >= ('a').ord && (hexa[i]).ord <= ('f').ord)
			
				#  When of hexadecimal digit is an lowercase letter
				decimal += ((hexa[i]).ord - 87) * self.power(16, digits - 1)
			elsif ((hexa[i]).ord >= ('A').ord && (hexa[i]).ord <= ('F').ord)
			
				#  When of hexadecimal digit is an uppercase letter
				decimal += ((hexa[i]).ord - 55) * self.power(16, digits - 1)
			else
			
				return
			end
			i += 1
			digits -= 1
		end
		digits = self.octal(decimal)
		if (flag == 1)
		
			digits = -digits
		end
		print("Hexa  : ", hexa ," Octal  : ", digits)
		print("\n")
	end
end
def main()

	obj = MyNumber.new()
	# Test Case
	obj.hexa_octal("A1")
	obj.hexa_octal("1A")
	obj.hexa_octal("f6")
	obj.hexa_octal("3E8")
	obj.hexa_octal("-E8")
end
main()

Output

Hexa  : A1 Octal  : 241
Hexa  : 1A Octal  : 32
Hexa  : f6 Octal  : 366
Hexa  : 3E8 Octal  : 1750
Hexa  : -E8 Octal  : -350
/*
  Scala Program
  Convert hexadecimal to octal number
*/
class MyNumber
{
	def power(number: Int, size: Int): Int = {
		if (size == 0)
		{
			return 1;
		}
		if (number == 0)
		{
			return 0;
		}
		else
		{
			var result: Int = number;
			var i: Int = 2;
			while (i <= size)
			{
				result = result * number;
				i += 1;
			}
			return result;
		}
	}
	//Convert decimal number into octal
	def octal(num: Int): Int = {
		var result: Int = 0;
		var multiplier: Int = 1;
		var remainder: Int = 0;
      	var number: Int = num;
		while (number != 0)
		{
			remainder = number % 8;
			result = (remainder * multiplier) + result;
			multiplier *= 10;
			number = (number / 8).toInt;
		}
		return result;
	}
	def hexa_octal(hexa: String): Unit = {
		if (hexa.length() <= 0)
		{
			return;
		}
		var decimal: Int = 0;
		var digits: Int = 0;
		var flag: Int = 0;
		var i: Int = 0;
		if (hexa(i) == '-')
		{
			flag = 1;
		}
		i = flag;
		while (i < hexa.length())
		{
			digits += 1;
			i += 1;
		}
		//First convert hexadecimal to decimal number
		i = flag;
		while (i < hexa.length())
		{
			if (hexa(i) >= '0' && hexa(i) <= '9')
			{
				//When hex digit, is a number
				decimal += (hexa(i) - 48) * power(16, digits - 1);
			}
			else if (hexa(i) >= 'a' && hexa(i) <= 'f')
			{
				// When of hexadecimal digit is an lowercase letter
				decimal += (hexa(i) - 87) * power(16, digits - 1);
			}
			else if (hexa(i) >= 'A' && hexa(i) <= 'F')
			{
				// When of hexadecimal digit is an uppercase letter
				decimal += (hexa(i) - 55) * power(16, digits - 1);
			}
			else
			{
				return;
			}
			i += 1;
			digits -= 1;
		}
		digits = octal(decimal);
		if (flag == 1)
		{
			digits = -digits;
		}
		print("Hexa : " + hexa + " Octal : " + digits);
		print("\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyNumber = new MyNumber();
		//Test Case
		obj.hexa_octal("A1");
		obj.hexa_octal("1A");
		obj.hexa_octal("f6");
		obj.hexa_octal("3E8");
		obj.hexa_octal("-E8");
	}
}

Output

Hexa : A1 Octal : 241
Hexa : 1A Octal : 32
Hexa : f6 Octal : 366
Hexa : 3E8 Octal : 1750
Hexa : -E8 Octal : -350
/*
  Swift Program
  Convert hexadecimal to octal number
*/
class MyNumber
{
  func power(_ number: Int, _ size: Int) -> Int
  {
    if (size == 0)
    {
      return 1;
    }
    if (number == 0)
    {
      return 0;
    }
    else
    {
      var result: Int = number;
      var i: Int = 2;
      while (i <= size)
      {
        result = result * number;
        i += 1;
      }
      return result;
    }
  }
  //Convert decimal number into octal
  func octal(_ num:  Int) -> Int
  {
    var result: Int = 0;
    var multiplier: Int = 1;
    var remainder: Int = 0;
    var number : Int = num;
    while (number != 0)
    {
      remainder = number % 8;
      result = (remainder * multiplier) + result;
      multiplier *= 10;
      number /= 8;
    }
    return result;
  }
  func hexa_octal(_ data: String)
  {
    var hexa = Array(data)
    if (hexa.count <= 0)
    {
      return;
    }
    var decimal: Int = 0;
    var digits: Int = 0;
    var flag: Int = 0;
    var i: Int = 0;

    if (hexa[i] == "-")
    {
      flag = 1;
    }
    i = flag;
    while (i < hexa.count)
    {
      digits += 1;
      i += 1;
    }
    //First convert hexadecimal to decimal number
    i = flag;
    while (i < hexa.count)
    {
      if (hexa[i] >= "0" && hexa[i] <= "9")
      {
        //When hex digit, is a number
        decimal += (Int(UnicodeScalar(String(hexa[i]))!.value) - 48) * self.power(16, digits - 1);
      }
      else if (hexa[i] >= "a" && hexa[i] <= "f")
      {
        // When of hexadecimal digit is an lowercase letter
        decimal += (Int(UnicodeScalar(String(hexa[i]))!.value) - 87) * self.power(16, digits - 1);
      }
      else if (hexa[i] >= "A" && hexa[i] <= "F")
      {
        // When of hexadecimal digit is an uppercase letter
        decimal += (Int(UnicodeScalar(String(hexa[i]))!.value) - 55) * self.power(16, digits - 1);
      }
      else
      {
        return;
      }
      i += 1;
      digits -= 1;
    }
    digits = self.octal(decimal);
    if (flag == 1)
    {
      digits = -digits;
    }
    print("Hexa : ", data ," Octal : ", digits, terminator: "");
    print("\n", terminator: "");
  }
}
func main()
{
  let obj: MyNumber = MyNumber();
  //Test Case
  obj.hexa_octal("A1");
  obj.hexa_octal("1A");
  obj.hexa_octal("f6");
  obj.hexa_octal("3E8");
  obj.hexa_octal("-E8");
}
main();

Output

Hexa :  A1  Octal :  241
Hexa :  1A  Octal :  32
Hexa :  f6  Octal :  366
Hexa :  3E8  Octal :  1750
Hexa :  -E8  Octal :  -350

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved