Skip to content

Logic Quest

VLSI Interview Questions

  • Wave Diagram Analysis
  • Design Questions
  • Gate Level Questions
  • Some Coding
  • Contact us
  • Toggle search form

Convert to Binary

Wrtie a function that get a number and returns its binary representation.

int toBinary(int num)

Answer

int toBinary(int num) {
	if (num == 0) {
		return 0;
	}
	return num % 2 + 10 * toBinary(num / 2);
}
INPUT  : 6
OUTPUT : 110

INPUT  : 15
OUTPUT : 1111

INPUT  : 50
OUTPUT : 110010

Next Question>>>

Copyright © 2023 Logic Quest.

Powered by PressBook Blog WordPress theme