473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mySqlBytes.buff er is getting converted to BigEndian even though both SQL server 2005 and the CLR function are on the same machine which shows BitConverter.Is LittleEndian == true

DR
mySqlBytes.buff er is getting converted to BigEndian even though both SQL
server 2005 and the CLR function are on the same machine which shows
BitConverter.Is LittleEndian == true

in tsql: select * from dbo.MY_CLR_FUNC TION(cast(1024 as binary(4)))

public static int MY_CLR_FUNCTION (SqlBytes mySqlBytes)

in debugger binaryData.buff er now shows bigendian!!
[0] 0 byte
[1] 0 byte
[2] 4 byte
[3] 0 byte

the data stays littleendian if the integer is hard coded in C#:

int myint;
myint = 1024;
byte[] b = new byte[4];
b = BitConverter.Ge tBytes(myint);

in debugger binaryData.buff er shows littleendian
[0] 0 byte
[1] 4 byte
[2] 0 byte
[3] 0 byte
in all cases BitConverter.Is LittleEndian shows true, so why is the integer
hard coded in tsql getting converted to big endian when it arrives in a clr
function?
Jan 4 '08 #1
1 1989
The point is that it is not being converted to any-endian.

binary(4) is nothing more that a buffer of bytes and cast(... as binary(4))
is certainly NOT analogous to BitConverter.Ge tBytes(int).

If you want it correctly then pass the int (intact) to the function and use
BitConverter inside the function.
"DR" <so************ *******@yahoo.c omwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
mySqlBytes.buff er is getting converted to BigEndian even though both SQL
server 2005 and the CLR function are on the same machine which shows
BitConverter.Is LittleEndian == true

in tsql: select * from dbo.MY_CLR_FUNC TION(cast(1024 as binary(4)))

public static int MY_CLR_FUNCTION (SqlBytes mySqlBytes)

in debugger binaryData.buff er now shows bigendian!!
[0] 0 byte
[1] 0 byte
[2] 4 byte
[3] 0 byte

the data stays littleendian if the integer is hard coded in C#:

int myint;
myint = 1024;
byte[] b = new byte[4];
b = BitConverter.Ge tBytes(myint);

in debugger binaryData.buff er shows littleendian
[0] 0 byte
[1] 4 byte
[2] 0 byte
[3] 0 byte
in all cases BitConverter.Is LittleEndian shows true, so why is the integer
hard coded in tsql getting converted to big endian when it arrives in a
clr function?
Jan 5 '08 #2

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

Similar topics

303
17589
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
4
41853
by: Stephan Steiner | last post by:
Hi I have a networking application that periodically needs to go into sleep mode (from an application point of view, I'm simply suspending the receiver thread until it's time to start listening to incoming packets again). The packets I'm interested in are UDP broadcasts, so they are simply dropped when nobody application is listening at the specified port. However, when I initialize my receiver, there's a socket listening at the...
14
19034
by: Laszlo Szijarto | last post by:
Can BinaryReader be forced to read a stream, say a TCP/IP stream or memory stream or even file stream in big endian order or do I have to write something custom to reverse the byte order? So, for example, I'd like a Windows client PC (native little endian) to be able to read a network stream coming in as big endian. I want to be able to read a short for example without worrying about flipping the bytes. Thank you, Laszlo
6
7237
by: BMax | last post by:
Hello I want to create a byte and use it as a buffer, then access it with a binaryreader or streamreader. what is important is to be able to read different variables form that, like readint16, readbytes(),readint32.... . so if there is a method to read byte arrays that would also help. (i couldn' use convert class ) is that possible? if yes how?
7
8117
by: Lenn | last post by:
This probably something stupid, or I am missing some fundemantal concept, but I can't figure this one out. Consider the following code: byte bd = new byte; bd = 0x00; bd = 0x01; System.Int16 a;
6
20085
by: Sameh Ahmed | last post by:
Hello there I need to get the "PwdLastSet" of a user object to know when he last set his password. I am using DirectoryServices.DirectoryEntry to bind to the user object, but it either gives "Argument 'Prompt' cannot be converted to type 'String'." or when I use .tostring it returns "system._comobject" I even tried to use this line but it also failed dater.FromFileTimeUtc(entry.Properties("pwdlastset").Value) 'ast from type...
19
8018
by: docschnipp | last post by:
Hi, as someone pulling to C# over from C++ I stumbled over something today for which I was not able to find an answer: HOW do I convert a byte block with a given endianess to an int32 and vice versa? In C++ I have this:
331
14828
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and most versatile text editor. And, besides text editing, it also serves as a
64
9707
by: Philip Potter | last post by:
Hello clc, I have a buffer in a program which I write to. The buffer has write-only, unsigned-char-at-a-time access, and the amount of space required isn't known a priori. Therefore I want the buffer to dynamically grow using realloc(). A comment by Richard Heathfield in a thread here suggested that a good algorithm for this is to use realloc() to double the size of the buffer, but if realloc() fails request smaller size increments...
0
8379
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
8294
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
8709
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8596
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
5627
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
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
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
1924
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.