endianness

SQL Server binary(128) convert from little endian to big endian

主宰稳场 提交于 2019-12-06 20:33:14
问题 how to convert a binary(128) from little endian to big endian in SQL Server? 回答1: try something like this: declare @little binary(4) set @little = 0x02010000 select @little [bigEndian], cast(reverse(@little) as binary(4)) [littleEndian] OUTPUT: bigEndian littleEndian ---------- ------------ 0x02010000 0x00000102 (1 row(s) affected) 来源: https://stackoverflow.com/questions/2416557/sql-server-binary128-convert-from-little-endian-to-big-endian

Function convert Hex String to BitArray C#

核能气质少年 提交于 2019-12-06 14:29:44
问题 I created the following function which will do as requested (convert HEX string to BitArray). I am not sure about the efficiency of the function, but my main problem now is that the Convert.ToInt64 function is endian specific . When this is ported over to alternate chipsets we will get different results (or exceptions). So can anyone think of an alternate way to do this conversion??? public BitArray convertHexToBitArray(string hexData) { string binary_values = ""; BitArray binary_array; if

Swapping endiannes in C

偶尔善良 提交于 2019-12-06 14:00:17
问题 I have this string c1eb044f0708015b267913fc4dff5aabe3dd4a97f10f7ba935cd360000000000 How does one swap it so it becomes 000000000036cd35a97b0ff1974adde3ab5aff4dfc1379265b0108074f04ebc1 Those two are basically examples, but that is what i need to do, but not know how as i have very little knowledge of C. The above two strings are actually unsigned char[] in the C program P.S Don't think i didn't go through google. I did, but i found very little of what i needed so every attempt to do that

Endianness conversion and g++ warnings

有些话、适合烂在心里 提交于 2019-12-06 13:37:20
I've got the following C++ code : template <int isBigEndian, typename val> struct EndiannessConv { inline static val fromLittleEndianToHost( val v ) { union { val outVal __attribute__ ((used)); uint8_t bytes[ sizeof( val ) ] __attribute__ ((used)); } ; outVal = v; std::reverse( &bytes[0], &bytes[ sizeof(val) ] ); return outVal; } inline static void convertArray( val v[], uint32_t size ) { // TODO : find a way to map the array for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++) v[i] = fromLittleEndianToHost( v[i] ); } }; Which work and has been tested (without the used

Platform independent storage of signed integers

吃可爱长大的小学妹 提交于 2019-12-06 11:23:22
问题 I want to write signed integer values into a file in a platform independent way. If they were unsigned, I would just convert them from host byte order to LE (or BE) with the endian(3) family of functions. I'm not sure how to deal with signed integers though. If I cast them to unsigned values, I loose the sign, since the C standard does not guarantee that (int) ((unsigned) -1)) == -1 The other option would be to I cast a pointer to the value (i.e., reinterpret the byte sequence as unsigned),

how can I use linux command sed to process Little-endian UTF-16 file

☆樱花仙子☆ 提交于 2019-12-06 04:54:28
问题 I am working on an application about windows rdp. Now I get a problem when I try to use the sed command to replace the string of IP address directly in the rdp file. But after executing this command, the origin rdp file is garbled. sed -i "s/address:s:.*/address:s:$(cat check-free-ip.to.rdpzhitong.rdp)/" rdpzhitong.rdp I find that the file's format is Little-endian UTF-16 Unicode. Can I still use the sed command to replace the text in the files correctly? Or other method to process this

How are array values stored in Little Endian vs. Big Endian architecture

Deadly 提交于 2019-12-06 04:25:45
I am inquiring about how to tell when one element in an array has finished and another is beginning in an endian architecture. I have 2 arrays where the size of long is 8 and the size of char is 1 long x[2] = {0x012345,0xFEDC}; char c[12] = {'a','b','c','d','e','f','g','h','0','1','2','3'}; And I was wondering how these values would be stored in the different Endian architectures if we consider x starting at memory address 0x100 and c starting at memory address 0x200 . I thought that the Big Endian address would be {01,23,45,FE,DC} where the first element of the set is at memory address 0x100

How to properly get little-endian integer in java

只愿长相守 提交于 2019-12-06 04:24:32
I need to get 64-bit little-endian integer as byte-array with upper 32 bits zeroed and lower 32 bits containing some integer number, let say it's 51. Now I was doing it in this way: byte[] header = ByteBuffer .allocate(8) .order(ByteOrder.LITTLE_ENDIAN) .putInt(51) .array(); But I'm not sure is it the right way. Am I doing it right? What about trying the following: private static byte[] encodeHeader(long size) { if (size < 0 || size >= (1L << Integer.SIZE)) { throw new IllegalArgumentException("size negative or larger than 32 bits: " + size); } byte[] header = ByteBuffer .allocate(Long.BYTES)

how are integers stored in memory?

亡梦爱人 提交于 2019-12-06 03:47:59
I'm confused when I was reading an article about Big/Little Endian. Code goes below: #include <iostream> using namespace std; int i = 12345678; int main() { char *p = (char*)&i; //line-1 if(*p == 78) //line-2 cout << "little endian" << endl; if(*p == 12) cout << "big endian" << endl; } Question: In line-1, can I do the conversion using static_cast<char*>(&i) ? In line-2, according to the code, if it's little-endian, then 78 is stored in the lowest byte, else 12 is stored in the lowest byte. But what I think is that, i = 12345678; will be stored in memory in binary. If it's little-endian, then

How to get the double value using libpq?

↘锁芯ラ 提交于 2019-12-06 02:19:21
The examples in the libpq documentation show how to get the the integer value by converting it to the host-endian representation. I am curious what must be done to get the double precision value using libpq (without libpqtyppes)? I have tried reinterpret_cast with no luck. Also why text and byte data doesn't need endian conversions? The DB runs locally on Windows 7, I am using Visual C++ 2013. pptr is a double vaule I am trying to retrieve. #include <iostream> #include <memory> #include <vector> #include <libpq-fe.h> #include <Winsock2.h> static void show_binary_results(PGresult *res) { int i,