byte

What is the best way to convert Bytes to Cardinal and vice versa

I have The following code for now. type TByte4 = array[0..3] of Byte; // 32-bit function CardinalToBytes(const Data: Cardinal): TByte4; begin Result[0] := (Data shr 24) and 255; Result[1] := (Data shr 16) and 255; Result[2] := (Data shr 8) and 255; Result[3] := Data and 255; end; function BytesToCardinal(const Data: TByte4):...

Get File Bytes from Resource file in C#

I used to store the resources in the actual project, but I've switched to using a resource file instead. Originally I could ready the bytes for a file, but I'm finding it difficult doing this with a resource file. Any suggestions would be greatly appreciated. ...

Bit/byte conversion

How many bits is a .NET string that's 10 characters in length? (.NET strings are UTF-16, right?) ...

How to convert floating-point to unsigned variable ?

Hi everyone, Could someone please help me with byte ordering regarding floating point variables? Actually the code is working correctly on Solaris, but not on Windows Xp. Here is a piece example of my code: .... int x_snd=1; float y_snd=1.13; struct { int xx_snd; float yy_snd; } data_snd; int x_rec; float y_rec; ...

Tips on building a byte protocol

I'm communicating data between devices, and I have to program the protocol as an array of bytes. Any tips when building protocols at a low-level? .. Eg: Use a 2 byte header, to send the length of the message before the data bytes. Use a CRC/data validation scheme. (How do I do this? Any simple checksums?) ...

IOWriteBytesPersec is actually total bytes?

The documentation for the Windows WMI counter Win32_PerfRawData_PerfProc_Process.IOWriteBytesPersec says it's number of bytes per second, but it behaves like a total. For example, the same data is viewable in task manager as "I/O Write Bytes" but the value only ever seems to go up, never down. The same goes for read byte...

How to print bytes using System.out.println ?

Hi all, I've declared a byte array (I'm using Java): byte test[] = new byte[3]; test[0] = 0x0A; test[1] = 0xFF; test[2] = 0x01; How could I print the different values stored in the array? If I use System.out.println(test[0]) it will print '10'. I'd like it to print 0x0A Thanks to everyone! ...

How to get the size of an image in bytes with Delphi?

Hi dudes, my app has 3 controls: TThumbnailList (image viewer from TMS components), TImage, and TLabel. I wish that when I drag an image from TThumbnailList to TImage, and drop it, the TLabel object shows the size in bytes for that image. How do I get this? Thanks in advance. procedure TForm1.AssignImage; begin //tl: TThumbnailList ...

US-ASCII encoding with Odd and Even numbers?

I splitted the list of numbers 1-100 to files of 2 bytes. Then, I noticed that each odd number btw 11-99 needs 2 files, ie 4bytes, while each even number btw 11-99 needs 1 file, 2bytes. A file is enough for numbers btw 1-10. You can confirm the finding below. How can you explain the finding? What did I do? save numbers to a file, lik...

Can java floats be sorted by their byte representations?

I'm working in Hadoop, and I need to provide a comparator to sort objects as raw network order byte arrays. This is easy for me to do with integers -- I just compare each byte in order. I also need to do this for floats. I think, but I can't find a reference, that the IEEE 754 format for floats used by Java can be sorted by just comparin...

#1071 - Specified key was too long; max key length is 767 bytes

When I executed the following command: ALTER TABLE `mytable` ADD UNIQUE ( `column1` , `column2` ); I got this error message: #1071 - Specified key was too long; max key length is 767 bytes Information about column1 and column2: column1 varchar(20) utf8_general_ci column2 varchar(500) utf8_general_ci I think varchar(20) only req...

Get byte size of List<T>

Hi, Silly question, but in a winforms app Im currently working on, I would like to get the amount of bytes allocated/used by a List<[SomeObject]> held in memory (for statistical purposes). Is this possible? I have searched thru the possible options, but there is obviously no myList.GetTotalBytes() method. ...

Codec Errors in Python

Does anyone know the name of a codec that can translate any random assortment of bytes into a string? I have been getting the following error after encoding, encrypting, and decoding a string in tkinter.Text. UnicodeDecodeError: 'utf8' codec can't decode byte 0x99 in position 151: unexpected code byte Code used to generate the error f...

Working with Byte literals

I'm using the following function to brighten up color values (it's a lambda in my code, but that shouldn't make a differende): Function ReduceDistanceTo255(ByVal i As Byte) As Byte Return i + (255 - i) \ 2 End Function It won't compile, since the compiler interprets 255 and 2 as integers rather than bytes, making the result of typ...

How to use C#'s ternary operator with two byte values?

There doesn't seem to be a way to use C#'s ternary operator on two bytes like so: byte someByte = someBoolean ? 0 : 1; That code currently fails to compile with "Cannot convert source type 'int' to target type 'byte'", because the compiler treats the numbers as integers. Apparently there is no designated suffix to indicate that 0 and ...

How to represent the top 8 bytes of the MD5 hash of the bytes of the given String's UTF-8 encoding as a long in java?

How to represent the top 8 bytes of the MD5 hash of the bytes of the given String's UTF-8 encoding as a long in java? ...

How to get bytes out of a PNG file using C#

How do I get bytes out of a PNG file using C#, (Reason for this:I need to pass the PNG as a string in an XML file.) ...

Javascript variable type (byte).

I searched for javascript byte type variables and I can't find byte type variable??? Thanks. ...

How to convert a bitmap to int[]?

Hi there! I'm writing a program to do some image processing on the GPU. For this I'm using CUDA.Net, but unfortunaly the CUDA doesn't recognize the type byte, in which I was able to store the pixels information using this code: BitmapData bData = bmp.LockBits(new Rectangle(new Point(), bmp.Size), ImageLo...

C: Comparing two bytes to see if one is within a certain range of the other

I am writing code that compares 2 bytes which represent integers. I want to see if byte R is with +-10 of G. The problem I am having with the code is with the comparison in the if-statment near the end. The bytes never come out as being out of range, even when they should. I am sure the problem comes from how I am adding/subtracting the ...