473,567 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between uint in C# and DWORD(unsigned long) in c



Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher( C) and (uint*)cipher(C #) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.

cipher is pointing to
" ;Configurationp age

[InstalledPerson alitiesAndOptio ns]
Personality=7

[ProductInformat ion]
ProductName=HP Laser Tablerock
FormatterNumber =HA0001s
PrinterNumber=Q 1234A
ProductSerialNu mber=XXXXXXXXXX
ServiceID=1001
FirmwareDatecod e=0629_07:30:39 Phoenix Firmware
MaxPrintResolut ion=0
ControllerNumbe r=1
TeleconVersion= 06-015-001
ADFInstalled=1

[EventLog]
NumberEntriesUs e=9
MaximumNumberEn tries=10

[ProductSettings]
DeviceDescripti on=HP Laser Tablerock
DeviceLanguage= 1"

Thank You

*** Sent via Developersdex http://www.developersdex.com ***
Dec 14 '05 #1
4 13016
Virajitha,

Without knowing what the declaration of the function is, it's impossible
to say. However, you say that a DWORD is an unsigned long. If you are
referring to an unsigned long in C#, then you would be wrong, because that
is an eight byte unsigned value, while a DWORD is a four byte unsigned
value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Virajitha Sarma" <vi************ **@yahoo.com> wrote in message
news:ev******** ******@TK2MSFTN GP12.phx.gbl...


Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher( C) and (uint*)cipher(C #) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.

cipher is pointing to
" ;Configurationp age

[InstalledPerson alitiesAndOptio ns]
Personality=7

[ProductInformat ion]
ProductName=HP Laser Tablerock
FormatterNumber =HA0001s
PrinterNumber=Q 1234A
ProductSerialNu mber=XXXXXXXXXX
ServiceID=1001
FirmwareDatecod e=0629_07:30:39 Phoenix Firmware
MaxPrintResolut ion=0
ControllerNumbe r=1
TeleconVersion= 06-015-001
ADFInstalled=1

[EventLog]
NumberEntriesUs e=9
MaximumNumberEn tries=10

[ProductSettings]
DeviceDescripti on=HP Laser Tablerock
DeviceLanguage= 1"

Thank You

*** Sent via Developersdex http://www.developersdex.com ***

Dec 14 '05 #2

Hi,

Thank you for ur help...

But like DWORD, uint also takes 4 bytes. So I donot think there is any
mismatch in that.

function Declaration in C# :
/unsafe
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_enc ipher((uint*)ci phPtr , (uint*)(ciphPtr +4) );

in C:
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_enc ipher((DWORD*)c iphPtr ,(DWORD*)(ciphP tr+4));

*** Sent via Developersdex http://www.developersdex.com ***
Dec 14 '05 #3

"Virajitha Sarma" <vi************ **@yahoo.com> wrote in message
news:ev******** ******@TK2MSFTN GP12.phx.gbl...


Hi,

I have a code in C which i am rewritting it in C#.

I am facing problem with the following two lines :

char *cipher;
(DWORD*)cipher( C) and (uint*)cipher(C #) are giving different values
though both DWORD(which is unsigned long) and uint occupy 4 bytes
Why is it happening ? Any insight into this topic would be highly
helpful.


Not sure what you are trying, posting some real code would help.

char* cipher
is a pointer to a char.
in both C and C# (unsafe context?) you cast cipher to a unsigned int
pointer and you expect that ciper has the same value, right? Wrong, a char
in C is a 8 bit value, while in C# it's a 16bit value. So when you point to
a char from C# and cast the value to an uint, 16 bits will be taken as
source, while when you cast from a char* in C only 8 bits will be taken.
So, in C# you need to consider a C char* as a byte*.

Willy.

Dec 14 '05 #4
On Tue, 13 Dec 2005 21:18:26 -0800, Virajitha Sarma wrote:

Hi,

Thank you for ur help...

But like DWORD, uint also takes 4 bytes. So I donot think there is any
mismatch in that.

function Declaration in C# :
/unsafe
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_enc ipher((uint*)ci phPtr , (uint*)(ciphPtr +4) );

in C:
char* ciphPtr = cipher;(cipher is a char array)
BlowFishEnc_enc ipher((DWORD*)c iphPtr ,(DWORD*)(ciphP tr+4));

*** Sent via Developersdex http://www.developersdex.com ***


Maybe, instead of trying to force a token per token translation of the
code, step back and try to understand what is happening, and then proceed
from there.

It looks like you are trying to pass in the memory location of
the begining of the character array and then the memory location of the
4th character in the array ? Is that correct ?

Though this may work, I would suggest that you use the C# language to your advantage, and not try
to force pointer manipulations on the code.

Dec 14 '05 #5

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

Similar topics

36
2859
by: Song Yun Zhao | last post by:
Hi, Just wondering what are the dis/advantages of using uint vs int. When would be the best time to use it? Personally I don't use uint that much, but I like to optimize my code and make it as effective as possible. So I feel that using an int where only an uint is needed is a waste. e.g. something like (int i = 0; i < 100; i++)
10
11124
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 storing IP address in their integer form (ie. 32 bits) and Long Integer because it is signed can not represent the full range needed (0..4294967295),...
19
2048
by: junky_fellow | last post by:
How the unsigned to signed integet conversion is done ? For eg: unsigned int ui = 100; int si = ui; What will be the value if "si" is printed ? How this conversion is done ? Thanx for any help in advance ....
20
5323
by: Hanzac Chen | last post by:
Hi, I don't understand why this could happen? The Code 1 will output `fff9' and the Code 2 will output `1' How could the `mod 8' not have effect? /* Code 1 */ #include <stdio.h> #include <stdlib.h>
3
1489
by: muesliflakes | last post by:
I come from Java and an Object would be the class whist object would likly be the varible to an object. I get the impression with C# that object is just an alias to the Base Class Object. Can anyone enlighten me as to any differences and by convention if I had a method that returns an object should I use one over the other. public...
22
591
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to 'Integer'. ' other stuff.. End With
3
41917
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned 0x%x\n",(unsigned char)b); }
3
36495
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) { }
4
6170
by: CedricCicada | last post by:
Greetings! I am trying to write a color class that is a bit more intelligent that C#'s System.Color structure. This means that I'm using a bunch of bitmasks. My class has the following method: public static HTColor FromArgb(int argb) { int colorValue = 0; int transparency = (argb & 0xff000000) >24;
0
7688
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...
0
7590
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7905
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. ...
0
8115
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7651
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...
0
6272
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...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2093
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 we have to send another system
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.