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 is stack pointer value 07h?

The stack pointer value of 07h typically indicates the current position of the stack in memory, often reflecting where the next data will be pushed or popped. In a system using hexadecimal notation, 07h corresponds to the decimal value of 7, which may represent a specific memory offset within the stack segment. This value can change dynamically during program execution as data is pushed to or popped from the stack. Ultimately, the stack pointer's value helps manage the call and return addresses, local variables, and function parameters in a program's execution context.


What is a Bit-stack traversal?

Bit-stack traversal is a method used in computer science and data structures to navigate through a collection of bits or binary values organized in a stack-like structure. This traversal technique typically involves manipulating and accessing bits based on a last-in, first-out (LIFO) principle, allowing for efficient processing of binary data. It is often utilized in algorithms that require bit manipulation, such as compression or encryption processes. Overall, bit-stack traversal optimizes how binary information is accessed and processed in various applications.


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.

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


How do you convert expression to binary tree?

To convert an expression to a binary tree, you can use the Shunting Yard algorithm to first convert the expression from infix to postfix notation (Reverse Polish Notation). Then, iterate through the postfix expression, using a stack to create nodes for each operand and operator. For each operator, pop the required number of operands from the stack, create a new node for the operator, and link the operands as its children. Finally, push the new node back onto the stack until the expression is fully processed, resulting in a binary tree representing the expression.


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.


Why is stack pointer value 07h?

The stack pointer value of 07h typically indicates the current position of the stack in memory, often reflecting where the next data will be pushed or popped. In a system using hexadecimal notation, 07h corresponds to the decimal value of 7, which may represent a specific memory offset within the stack segment. This value can change dynamically during program execution as data is pushed to or popped from the stack. Ultimately, the stack pointer's value helps manage the call and return addresses, local variables, and function parameters in a program's execution context.


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.


What is a bit stack traversal?

Bit stack traversal refers to the process of navigating through a stack data structure that stores bits, typically for purposes like data compression, encoding, or manipulation. In this context, a "bit stack" may involve operations such as pushing and popping bits, allowing for efficient access and modification of binary data. This traversal can be used in algorithms that require bit-level operations, such as parsing binary files or implementing certain data structures like tries or binary trees.