473,471 Members | 4,095 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Print binary numbers from 0 to M. Size N bits. Ascend

3 New Member
Hello,
I need help writing a program that print binary numbers from 0 to M.
Size N bits.
Ascending or descending order according to user choice.
When the default is M = 8, N = 3

Thank you
Apr 26 '14 #1
5 1561
weaknessforcats
9,208 Recognized Expert Moderator Expert
All numbers are binary in the computer. Do you mean you want to take a value like 5 and print 101?
Apr 26 '14 #2
elieli
3 New Member
no,
insert in the begining a value to M,N. (define M 8, define N 3).

and then the program need to print the all binar numbers from 0 to M in N bytes by order.
Apr 26 '14 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
So if M is 8 and N is 3, what do you expect to print?
Apr 26 '14 #4
elieli
3 New Member
000
001
010
011
100
101
110
111
Apr 27 '14 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
So you are printing 101 for a value of 5.

You can use this algorithm to get the binary value from the integer value:

4/1 4 4%2 0
4/2 2 2%2 0
4/4 1 1%2 1

5/1 1 5%2 1
5/2 2 2%2 0
5/4 1 1%2 1


6/1 6 1%2 0
6/2 3 3%2 1
6/4 1 1%2 1


7/1 7 7%2 1
7/2 3 3%2 1
7/4 1 1%2 1

As you can see, to get the binary digit at a position you divide your value by the binary value at that position. The result will be odd or even. Then you use the % operator to see odd or even as 1 or 0.
Apr 27 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Douglas Soares de Andrade | last post by:
Hi ! How to work with binary numbers in python ? Is there a way to print a number in its binary form like we do with oct() or hex() ? Im doing a project that i have to work with binaries and i...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
6
by: Kelvin | last post by:
Hi everyone: when we wanna use hex numbers in C, we usually write something like: int hex_num = 0x12F9; but how can I declare a binary number in a similar way by putting some leading words to...
10
by: Craig | last post by:
Hi there, I'm trying to switch binary numbers around so that the MSB becomes the LSB etc. Is there an easy way of doing this as I can't seem to find anything. If you could help that would be...
2
by: shalombizal | last post by:
I am a student of Electrical Engineering I want to write a C++ program to realize arthimetic operation in binary. can any body help me by giving C++ code for signed mulitplication and Division of...
5
by: dmitrey | last post by:
hi all, could you inform how to print binary number? I.e. something like print '%b' % my_number it would be nice would it print exactly 8 binary digits (0-1, with possible start from 0) ...
0
by: castironpi | last post by:
On May 7, 3:31 pm, Mensanator <mensana...@aol.comwrote: ) for a in range( 10 ) ] ) 00000000 00000001 00000010 00000011 00000100 00000101 00000110
2
by: James Harris | last post by:
I'm trying to make sense of the standard C data sizes for floating point numbers. I guess the standards were written to accommodate some particular floating point engines that were popular at one...
7
by: victory2006 | last post by:
like we have an integer value of : 9 and i need to convert it to binary numbers and vice versa, thanks!
1
by: game2d | last post by:
i know how to insert, print binary tree but how to print it like this? note that leafs and nodes will change and dont have to be same as this. ex: 6 / \ 1 7 / / \ 0 5 8
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.