473,796 Members | 2,494 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 13025
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
2912
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
11161
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), neither can Double. Any suggestions please?
19
2077
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
5367
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
1501
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 object ReturnIt( ) { return new Blah( ); }
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
41949
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
36579
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
6187
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
9683
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
9529
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
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
10176
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
9054
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
7550
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
6792
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
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2927
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.