Write down a function to display an integer in binary format, C/C++ Programming

Assignment Help:

A: void displayBits( unsigned value )

{

const int SHIFT = 8 * sizeof( unsigned ) - 1;

const unsigned MASK = 1<< SHIFT;

cout << setw(10 ) << value << " = ";

for ( unsigned i = 1; i <= SHIFT + 1; i++ )

{

cout << ( value & MASK ? '1' : '0' );

value <<= 1;

if ( i % 8 == 0 ) // output a space after bits cout << ' ';

}

cout << endl;

}

You may do the same by divide by 2, till the number is greator than 0. However you ought to use stack to print it in reverse order.

 

 


Related Discussions:- Write down a function to display an integer in binary format

#title minimization and maxmization assignment problem, how we can code in ...

how we can code in c++ for assignment problem (operation research) method to mkinimization and mamization

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Basics, conceptual difference between big o,big thete and big omega

conceptual difference between big o,big thete and big omega

Explain the pointer types, Pointer Types Pointer holds the address of a...

Pointer Types Pointer holds the address of an object, permitting for the indirect manipulation of that object. They are used in creating linked data structures like lists, tree

Oops, write a c++ program to find the prime numbers

write a c++ program to find the prime numbers

Define auto pointer?, A: The simplest instance of a smart pointer is auto_p...

A: The simplest instance of a smart pointer is auto_ptr that is included in the standard C++ library. Auto Pointer only takes care of Memory leak & does nothing regarding dangling

I need p2p video streaming, Project Description: P2P media streaming bro...

Project Description: P2P media streaming browser (IE, Chrome, Firefox) plug-in needed that is compatible with Win Xp,7,8 that is Windows Firewall friendly Example like Swarm

How does a structure differ from an array, Question : (a) What is a str...

Question : (a) What is a structure? Provide a simple example of your own to illustrate this feature. (b) How does a structure differ from an array? (c) Describe a structu

C++, Program to print the total marks and percentage of the 3 students usin...

Program to print the total marks and percentage of the 3 students using array

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd