How to print out a number in binary format using C/C++

preview_player
Показать описание
In this video, I will show you how to convert an integer number to binary format string and display it using C/C++

Thank you for your support!
Рекомендации по теме
Комментарии
Автор

Saved me hours of coding, or searching for solutions.Thanks!

georgederleres
Автор

How about i want to set all binary into 16bits it is possible ?
I hope you read this

haroldsollorano
Автор

To print the unsigned 16 bit integer lfsr in binary, I just used these lines:
for (j = 16; j>0; j=j-1){
printf ("%1x", (lfsr>>(j-1)) & (0x1));
}
printf (" hex= %5x dec= %5d \n", lfsr, lfsr);

starryridge
Автор

Isn't right bit shifting >> faster than division by 2 and n & 1 == 0 instead of % operator? And you would not need to do big changes

Victor_Marius
Автор

like what is buffer, why did you put p++, what does _strrev() do ? and how to actually print a given number in binary?
not the numbers from 0 to 255

pzg
Автор

The last reverse step is not working :(. First is working but for the reverse part, I followed exactly like you and tried many different times but it's not working.

ThilebanTheEngineer
Автор

can you please explain why you did p++; and n=n/2;

alirezagyt
Автор

Sir, you would make me so happy if you would make your videos a bit longer with a bit more explanation

pzg
Автор

how would i be able to reverse the string without strrev? I've being going at it for a while, and I can't get it to work

smeadswanson
Автор

Another simpler way (in my opinion) would be doing this:
#include <iostream>
#include <cmath>
using namespace std;


int main(){
long long x;

cin>>x;
int k=log2(x);

for(int i=k;i>=0;i--)
{
if((x&(1<<i))==0)cout<<0;
else cout<<1;
}

}

eduarddez
visit shbcf.ru