473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Binary representatio of unsigned integer

#include <iostream>

using namespace std;
int ConvertToBinary (int);
int main()
{
int num;
cout << "Input Number";
cin >> num;
cout << ConvertToBinary(num);
return 0;
}

int ConvertToBinary(int n)
{
int binary;
for(int i = n; i > 0;i = int (i/2))
{
binary =i % 2;
cout << binary;
}
return binary;
}
// it should output 111 but it ouput 1111
Oct 4 '15 #1
1 1226
weaknessforcats
9,208 Expert Mod 8TB
The output of your function is 111.

But then you go on to display the return value of ConvertToBinary, which is 1 from the last iteration of your loop.

So you see 1111.
Oct 4 '15 #2

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

Similar topics

6
by: Monica Roman | last post by:
Hello everyone, My question is how to upload an unsigned integer so that it looks like an IP address in Oracle? A Perl program captures IP addresses from a log server and puts them into a .csv...
10
by: Peter Piper | last post by:
A Quick question if someone could help, im sure this has been asked before, but googling is getting me now where slowly. Is it possible to get an unsigned 32 bit integer field in Access. Im...
14
by: junky_fellow | last post by:
Can anybody please explain this: When a value with integer type is converted to another integer type other than _Bool, if the new type is unsigned, the value is converted by repeatedly...
20
by: barbara | last post by:
Hi, all I have to read a binary data which is four bytes and I need to use the following function to deal with data: Private Function BIT(ByVal Val As UInt32, ByVal BitNum As UInt32) As...
5
by: mkwong8888 | last post by:
We are unable to represent an unsigned integer with 16 bytes memory size. The current integer size is 4 bytes by default. There is no way for us to store large integer in this case. The valid...
4
by: Gary Wessle | last post by:
Hi I am writing a code to open a space delimited data file, return the number of rows and columns, as well as return the nth column where n is user define number. I put all the cells in a...
6
by: hijkl | last post by:
.. How to reverse all the bits in a unsigned integer? an signed integer (you have to keep the sign of the integer)?
5
by: lovecreatesbeauty | last post by:
why does printf get -1 for an unsigned integer? #include <stdio.h> int main(void) { unsigned int u = 0; u--;
4
by: Raymond | last post by:
Source: http://moryton.blogspot.com/2007/08/detecting-overflowunderflow-when.html Example from source: char unsigned augend (255); char unsigned const addend (255); char unsigned const sum...
1
by: cmdolcet69 | last post by:
I'm having issues with the code below. I get the message that Uinteger is not defined. I need to make this data type as a unsigned integer. Public Class GlobalMembers Public com1 As MSCOMM...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.