answersLogoWhite

0

ALGORITHM: function outputInBinary(Integer n) Stack s = new Stack while n > 0 do Integer bit = n modulo 2 s.push(bit) if s is fullthen return error end if n = floor(n / 2) end while while s is not empty dooutput(s.pop()) end while end function

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

How do you write a C program to convert a binary value to its octal equivalent?

To convert from binary to octal, bitwise AND the binary value with 0x8 (00000111 in binary) and push the value onto a stack. Right-shift (>>) the binary value by 3 bits and repeat until the binary value is zero. Pop the stack to build the left-to-right digits of the octal value. Using 10110100 as an example: 10110100 & 00000111 = 00000100 10110100 >> 3 = 00010110 00010110 & 00000111 = 00000110 00010110 >> 3 = 00000010 00000010 & 00000111 = 00000010 00000010 >> 3 = 00000000 Popping the values in order reveals 00000010, 00000110 and 00000100 (decimal 2, 6 and 4 respectively). Thus 10110100 binary is 0264 octal.


Write a program to convert hexadecimal to decimal numbers?

write an assembly language program to implement a stack. START: LXI SP,STACK ;initialize stack pointer LXI H,BINBYT ;point HL index to where binary number is stored MOV A,M ;transfer byte LXI H,OUTBUF ;point HL index to output-buffer memory CALL BINBCD HLT BINBCD: MVI B,100 ;load 100 into register B (power of ten holding register) CALL BCD ;call conversion for BCD3 MVI B,10 ;load 10 into register B CALL BCD ;call conversion for BCD2 MOV M,A ;store BCD1 RET


Why must the stack pointer be initialized at the beginning of every program?

Because the stack pointer marks the top of the stack. If it is not initialised, it is not possible to determine where the next stack frame will go.


Stack c language program of palindrome?

what ever you assume


What is difference between stack pointer and program counter?

Both of them are pointers, but otherwise they are completely unrelated. The former points to the current position of the stack, the latter points to the current instruction of the program.

Related Questions

Convert decimal number to binary number using stack?

becomes heavy because the ang decimal number ay marami kay sa sa stack ng tsinelas


C plus plus program that convert decimal to binary using the concept of stack?

#include<stdio.h> #include<stdlib.h> main() { int number,binary[10000],b=0; printf("Enter decimal number "); scanf("%d",&number); printf("\nBinary: "); for(;number;number/=2,b++) binary[b]=number%2; for(b--;b>-1;b--) printf("%d ",binary[b]); }


How do you write a C program to convert a binary value to its octal equivalent?

To convert from binary to octal, bitwise AND the binary value with 0x8 (00000111 in binary) and push the value onto a stack. Right-shift (>>) the binary value by 3 bits and repeat until the binary value is zero. Pop the stack to build the left-to-right digits of the octal value. Using 10110100 as an example: 10110100 & 00000111 = 00000100 10110100 >> 3 = 00010110 00010110 & 00000111 = 00000110 00010110 >> 3 = 00000010 00000010 & 00000111 = 00000010 00000010 >> 3 = 00000000 Popping the values in order reveals 00000010, 00000110 and 00000100 (decimal 2, 6 and 4 respectively). Thus 10110100 binary is 0264 octal.


Write a program to convert hexadecimal to decimal numbers?

write an assembly language program to implement a stack. START: LXI SP,STACK ;initialize stack pointer LXI H,BINBYT ;point HL index to where binary number is stored MOV A,M ;transfer byte LXI H,OUTBUF ;point HL index to output-buffer memory CALL BINBCD HLT BINBCD: MVI B,100 ;load 100 into register B (power of ten holding register) CALL BCD ;call conversion for BCD3 MVI B,10 ;load 10 into register B CALL BCD ;call conversion for BCD2 MOV M,A ;store BCD1 RET


Write a program to convert stack into queue using c language?

In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.


what are the sections of c program?

Well, the source program doesn't have sections, the binary format consist of parts like: read-only executable, read-only data, writeable data, stack, etc


What are the different sections of c program?

Well, the source program doesn't have sections, the binary format consist of parts like: read-only executable, read-only data, writeable data, stack, etc


What is the difference between stack pointer and program counter?

The stack pointer keeps track of the top of the stack used by the current thread. The program counter keeps track of the next instruction in a program. Both are registers and both store a memory address.


What is Stack overflow at line?

A stack overflow is a type of buffer overflow in which an array writes memory outside of the array boundaries. The keyword here is "stack". The stack is a section in memory in which local variables and other program data are kept for future reference. When the stack gets overflown, adjacent program memory, such as variables, pointers, etc, will be overwritten and cause your program to crash.


Stack program by using recursive method in c plus plus?

#include<iostream> #include<iomanip> #include<string> std::string dec_to_bin(unsigned dec) { std::string result = ""; char c = (dec & 0x1) + '0'; // 'push' char onto call stack if( dec >>= 1) result += dec_to_bin(dec); // recurse return result + c; // 'pop' char from call stack } int main() { // Print the first 256 binary numbers. for (unsigned num=0; num<256; ++num) { std::cout.fill(' '); std::cout << std::setw(10) << num << " decimal is "; std::cout.fill('0'); std::cout << std::setw(32) << dec_to_bin(num) << " binary\n"; } }


Why must the stack pointer be initialized at the beginning of every program?

Because the stack pointer marks the top of the stack. If it is not initialised, it is not possible to determine where the next stack frame will go.


Write a c program to perform stack operation?

int top=-1; int stack[10];