Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?



Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?..

Answer / Ankita Bansal

Yes, you can use base-2 constants in C by prefixing them with `0b`. Here's an example of declaring and using a base-2 constant:nn```cn#include <stdio.h>nnint main() {n unsigned int myNumber = 0b101010;n printf("myNumber in decimal: %d
", myNumber);nreturn 0;n}n``` Unfortunately, there is no direct `printf` format for binary output. To print a value in binary, you can convert the number to binary strings and then print each bit individually.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

how to generate the length of a string without using len funtion?

4 Answers  


write a c/c++ programthat connects to a MYSQL server and checks if the INNoDB plug in is installed on it.If so your program should print the total number of disk writes by MYSQL.

0 Answers   BirlaSoft,


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

1 Answers  


Design a program using an array that searches a number if it is found on the list of the given input numbers and locate its exact location in the list.

4 Answers  


#include<stdio.h> int main( ) { Int a=300, b, c; if(a>=400) b=300; c=200; printf(“%d%d ”, b, c); return0; }

1 Answers  


In a switch statement, explain what will happen if a break statement is omitted?

1 Answers  


Are the expressions * ptr ++ and ++ * ptr same?

1 Answers  


How can you restore a redirected standard stream?

1 Answers  


explain memory layout of a C program

2 Answers  


Write a programm such that if user enter 11.25 it roundup to 11 but if user enter 11.51 upto 11.99 it will round up to 12 i.e.;convert the floting point value into integer format as explain above..

2 Answers  


prog for 1st five prime numbers in 2^x - 1

0 Answers  


how to generate sparse matrix in c

3 Answers  


Categories