473,770 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnSigned Long

Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.
I am using MSVC++ 6.0

Any help please urgent....

Thanks
J.
Nov 15 '05 #1
9 2520
Joriveek wrote:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.
Please provide some more information (for example a small example
program showing your problem together with the output of this program).
I am using MSVC++ 6.0
Some people are lucky, others are not.....

Kind regards,
Johan

--
o o o o o o o . . . _____J_o_h_a_n_ __B_o_r_k_h_u_i _s___
o _____ || http://www.borkhuis.com |
.][__n_n_|DD[ ====_____ | jo***@borkhuis. com |(________|__ |_[_________]_|_____________ _______________ ____|

_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
== VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
Nov 15 '05 #2
Joriveek wrote:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.
#include <stdio.h>

int main(void)
{
unsigned int myvarz = 3000000000;
printf("%u\n",m yvarz);
return 0;
}
This is working in msvc++ 6.0 and gcc.Please post your code

Johan Borkhuis wrote: Some people are lucky, others are not.....

very true.

Nov 15 '05 #3

"Joriveek" <no****@please. com> wrote in message
news:de******** **@reader01.new s.esat.net...
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.
unsigned long myvarz = 3000000000

I am using MSVC++ 6.0

Any help please urgent....


The C language standard requires that type 'unsigned long'
can represent a minimum range of values from zero (0) through
4294967295, inclusive. Your value 3000000000 falls within
this range.
I compiled the following code with Microsoft
Visual C++ v6.0 :

#include <stdio.h>

int main()
{
unsigned long myvarz = 0;
myvarz = 3000000000;
printf("%lu\n", myvarz);
return 0;
}

I got output of:

3000000000
So perhaps you could specify what you mean by 'not taking'.
How did you verify there's a problem? With a debugger?
Did you print out the value? If so, which 'printf()' format
specifier did you use?
-Mike
Nov 15 '05 #4
"Joriveek" <no****@please. com> wrote in message
news:de******** **@reader01.new s.esat.net...
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0
I don't know what's not taking what, but long is at least 32-bit long, hence
unsigned long will fit your 3000000000 nicely.

But you'll have problems multiplying this number in integer arithmetics
(using longs only) by anything other than 1. If that's what you have, you
should probably use long long (or _int64 as per msvc++, which doesn't know
long long) or go for double or long double, which has more bits in mantissa
than simple long (up to 80 if I'm not mistaken are supported by x86/x87
FPU).
Any help please urgent....


Alive yet? :)
Alex
Nov 15 '05 #5
Joriveek wrote on 29/08/05 :
I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0


Check your ULONG_MAX (in <limits.h>) It could be not big enough for the
value you want.

In that case, you have several solutions:

Use a smaller value.
Use a larger type:
- [C99] long long or unsigned long long
- some extension of your IDE with '64' in its name...
Use a lower precision type (like a double).
Kill the dog.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
Nov 15 '05 #6

"Emmanuel Delahaye" <em***@YOURBRAn oos.fr> wrote in message
news:mn******** *************** @YOURBRAnoos.fr ...
Joriveek wrote on 29/08/05 :
I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0


Check your ULONG_MAX (in <limits.h>) It could be not big enough for the
value you want.


It is large enough. I suspect OP didn't tell us the
whole story.

-Mike
Nov 15 '05 #7
ma*******@gmail .com wrote:
Joriveek wrote:
Hi,

I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.


#include <stdio.h>

int main(void)
{
unsigned int myvarz = 3000000000;
printf("%u\n",m yvarz);
return 0;
}
This is working in msvc++ 6.0 and gcc.


It should 'work' on any implementation, but may print values
like 24064 since unsigned int is not required to have more than
16 value bits.

--
Peter

Nov 15 '05 #8
"Mike Wahler" <mk******@mkwah ler.net> writes:
"Emmanuel Delahaye" <em***@YOURBRAn oos.fr> wrote in message
news:mn******** *************** @YOURBRAnoos.fr ...
Joriveek wrote on 29/08/05 :
I want to store myvarz = 3000000000;

I have declared myvarz as unsigned long; still not taking.

I am using MSVC++ 6.0


Check your ULONG_MAX (in <limits.h>) It could be not big enough for the
value you want.


It is large enough. I suspect OP didn't tell us the
whole story.


He certainly didn't. The above is all the information the OP gave us,
except for the "Any help please urgent...." at the end of the article.
There's no reason to think he can't store the value 3000000000 in an
unsigned long, and no clue what he means by "still not taking".

If it's really urgent, presumably he'll be following this thread and
will jump in any moment with a clearer explanation of what he's asking
for. Until then, there's really no point in speculating.

I'm tempted to suggest that if somebody posts an unclear question, and
somebody else has posted a followup asking for clarification, we
should drop the thread. Unfortunately there doesn't seem to be any
good way to drop a thread.

To any newbies reading this:

If you're having a problem, please give us the information we need to
help you solve it. I understand that it's hard to know just what
information is needed, so sometimes we'll need to go back and forth a
couple of times. Some hints:

Provide a small complete (compilable and executable) program that
exhibits the problem. The "compilable and executable" part is
optional if the problem is that it won't compile or execute.

Don't use any system-specific headers. If you need them to
illustrate the problem, you need to post to a system-specific
newsgroup. If you don't know which headers are system-specific,
we'll be glad to offer advice. (We're sometimes a bit
over-sensitive about topicality, so be patient.)

Tell us what you expect the code to do and what it actually does.
If you get error messages, show them to us. Cut-and-paste both
the code and the error messages; don't try to summarize or re-type
them.

If your problem description is equivalent to "It doesn't work",
you're not giving us enough information.

These are not arbitrary rules; they're ways you can help us to help
you. Any extra time they cost you will be more than paid back in the
speed with which we can either give you an answer to tell you where to
find the people who can.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9

"Peter Nilsson" <ai***@acay.com .au> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
ma*******@gmail .com wrote:
Joriveek wrote:
> Hi,
>
> I want to store myvarz = 3000000000;
>
> I have declared myvarz as unsigned long; still not taking.


#include <stdio.h>

int main(void)
{
unsigned int myvarz = 3000000000;
printf("%u\n",m yvarz);
return 0;
}
This is working in msvc++ 6.0 and gcc.


It should 'work' on any implementation, but may print values
like 24064 since unsigned int is not required to have more than
16 value bits.


Note that the OP indicated he's using type 'unsigned long',
not 'unsigned int'. 'unsigned long' must contain at least
32 bits.

-Mike

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3607
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For example, consider this four-bit number: 1100 from this number I want to extract two numbers: 1000 and 100 had the four-bit number been 0101 I would want to extract 100 and 1. How should I do this? I wish I had some code to post but I don't...
34
16690
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1 - 3;
25
2683
by: amit | last post by:
Hi, What will happen in following scenario.. long a = -2; longlong b = a long c; c = *(ulonglong *)&b; b = c; also when
16
5142
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
9
3953
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
3
36570
by: tutush | last post by:
Hi there, I have problem with importing my C++ code to C#. The c++ looks like these extern _declspec(dllexport) const char* SendAndReceiveBufferedWrp(__int64 hConnection, const char* pchSendBuffer, int iCmdDataMode,unsigned long bufferLength, unsigned long * pulNumBytesRcved) { }
14
12326
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code is right??Or is it a right approch to do that?? unsigned long temp; temp= (unsigned long) buff; temp | =((unsigned long) buff) << 8;
7
5049
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are involved. The problem is that comparisons between signed and unsigned values are machine- dependent, because they depend on the sizes of the various integer types. For example, suppose that int is 16 bits
6
6458
by: Kislay | last post by:
Consider the following code snippet unsigned int i=10; int j= - 2; // minus 2 if(i>j) cout<<"i is greater"; else cout<<"j is greater"; Since i is unsigned , j is greater . I know why , but vaguely . Can
13
2054
by: Martin Wells | last post by:
I commonly use the likes of -1 for max unsigned values, or something like -7 to get 6 away from the max value; sort of like: unsigned x = ... if (-7 == x) puts("x is 6 away from its maximum"); Since I rarely use anything smaller than int, this has never been a problem. Obviously though, there'd be a problem if I tried:
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.