Single precision integer to 8 digit hex string
I need to convert a single precision integer to a MSB-LSB 8 digit hex string to send to a test machine via RS-232. So 15 needs to turn into 41700000. The best I have been able to do is get 15 to turn into 0000000F, which is correct but not in the MSB-LSB format I need. Any ideas?
Just typecast the SGL to U32 and format it with %08x.
Message Edited by altenbach on 05-30-2007 08:49 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
SGL-to-HEXstring.vi 8 KB
SGL-to-HEXstring.png 6 KB
Similar Messages
-
Single precision to hex string
Hello,
I was wondering how to typecast a SGL Or DBL into a hex string? I tried number to hex, and format into string, etc but can't seem to figure it out.
The stirring doesnt need a sgl/dbl and is fine but the heating needs to work at a decimal point. since the device must multiply the heating by 10 (inputting 80 degrees gives out 800 to the device and it sets it to 80 degrees) turning it into a hex string shouldn't be a problem but i can't seem to figure this out.
Any help would be appreciated.
Thanks
Attachments:
single to hex.JPG 33 KBI meant like this which most closely represents what you did for the U16 conversion at the bottom half of your code.
Attachments:
Example_VI.png 15 KB -
Cast string to single precision
Hi,
I try to write a communication between a PC and a DSP which is
programmed to
understand some kind of ModBus. I tried to use MBmaster.vi, a freeware
of AIRtech in the netherlands.
I was successfull to 90% after a very short time - I get back a string
from the DSP which makes sense.
The only problem is to *convert* the 4Byte=8Hex=32Bits(=IEEE754 single
precision format) into the LabView single precision number it does
represent .
In other programming languages like C I think I could do this easily
on a very low level procedure or with one of these dangerous casts.
As a newbie to LabView I could not found neither one VI to do this or
find out which simple combination of VIs could solve the problems.
Are there any cracks
here who know *the* easy solution??
Thanx & Regards
Urs Bögli"Doug (CapeFl)" wrote in message news:<[email protected]>...
> Did you check the VI functions under Functions>String>Additional
> String to Number Functions?
> There are quite a few for converting to/from Hex, etc. I've used them
> for concatenating 4-bit strings into an 8-bit string (to get an 8-bit
> byte/word), also converting to/from Hex using some of the VIs I
> mentioned.
> Good Luck, Doug
Dough,
as a programmer for twenty years I have some problems to understand the way
labview does work with types and casts - other languages are much clearer about it
- or have I not found the ultimative help area yet ???
May I ask you to send me the VI off list?
thanks
Urs -
Hex String of format "01:02:03:04:05:06" to Integer?
Yes, that is a Mac Address,
does anyone know if there is some "comfortable" conversion routine in Cocoa for converting Hex numbers from String to int?
The ":" could be stripped, of course, they are only delimiters for easier reading...
Many thanks for any suggestions!
Cheers,
ThomasAfter you strip the colons from the string try something like:
NSScanner *scan = [NSScanner scannerWithString:hexValue];
unsigned val;
[scan scanHexInt:&val];
'val' will now contain the integer value of the string. 'hexValue' is the hex string. You might need to prepend "0x" to the start of the string too, after removing the colons. -
Problems when changing hex string to integer.
Hi
I am trying to change a hex string to an integer. I have done this using the following code:
theinteger = Integer.parseInt(thestring, 16);
this works for every hex number up to 7fffffff (Hex). As soon as I go to 80000000 (Hex) a number format exception occurs.
Does any know why this is happening as the highest number I need to go to is ffffffff (Hex).
Thanksyou must parse it to long.
7FFFFFFFF is the highest number that a int can hold.
0x80000000 being the lowest negative number.
Anyway, parsing to long should take care of the problem. -
Can someone explain why doing a floating point conversion compromises digit of precision accuracy? For example, if I wire the double precision number "16.0001000" to the "to Single Precision Float" vi input, the output is "16.0000991".
I have an application in which this level of accuracy is critical. I can think of several work arounds, but I still would like a good explanation for why this is the case.
pmacJust use array to spreadsheet string on the DBL and write as text file (and an analogous operation for reading, converting back to DBL). Alternatively, you could make DBL version of "read/write spreadheet file" by editing them slightly and saving them under a new name elsewhere. Make sure to change the icon too, e.g. give it a different color.
If precision is that important, you might want to use binary files. The don't have any formatting loss at all.
Of course if this is just measurement data, don't be fooled by fake precision. even SGL has a 22 bit mantissa, so if your DAQ hardware acqures in 16 bits, SGL is plenty.
LabVIEW Champion . Do more with less code and in less time . -
Converting a Hex String to an Int
I have a quick question. I am attempting to encode an Integer as a Hex String using Integer.toHexString(), which produces a max of eight hex characters.
I then need to convert this string back to an integer. I tried using Integer.parseInt(string, 16), but this only works for positive integers, because it expects a negative number to be designated with a "-" sign, which is the behavior of Integer.toString(int, 16).
I do not wish to represent the "-" sign in that manner, because I want to minimize the length of the hex string.
This method is time-critical, and I would like it to be as simple as possible, so I am looking for a solution in the standard libraries. Does anybody know of a method to convert the eight character hex representation which includes the sign bit as part of the eighth character back to an int using a method provided by the libraries?int intVal = (int)Long.parseLong(str, 16);
-
Single Precision Floating Point Numbers to Bytes
Ok here is some code that i have written w hile back with some help from the support staff. It is designed to take in precision floating point numbers that are stored as 4 bytes and convert then to a decimal value. It works off of a udp input string and then also reformats the string. I have the ability to look at up to 4000 parameters from this one udp string. But now what i want to do is do the opposite of what i have written, and also perhaps get rid of the matlab i used in it as well. What i would like to be able to do is input a decimal value and then have it converted in to the 4 byte groupings that make up this decimal nd then have it inputed back in to a single long string witht hat grouping of bytes in the right order. A better explanation of what was done can be found on this website
http://www.jefflewis.net/XPlaneUDP_8.html
as the original code followed the "Single Precision Floating Point Numbers and Bytes" example on that site but what i want to do is "Going from Single Precision Floating Point Numbers to Bytes". The site also explains the udp string that is being represented. Also attached is the original code that i am trying to simply reverse.
Attachments:
x-plane_udp_master.vi 34 KBPerhaps what you are doing is an exercise in the programming of the math conversion of the bytes.
But if you are just interested in getting the conversion done, why not use the typecast function?
If the bytes happen to be in the wrong order for wherever you need to send the string, then you can use string functions to rearrange them.
Message Edited by Ravens Fan on 10-02-2007 08:50 PM
Attachments:
Example_BD.png 3 KB -
Storing analog output data in a datatype other than single-precision
I'm using three PCI-6713 AO cards in a single computer to output 24 channels of data using Labview 6.1. The input terminals of all the analog output VI's are of type single precision (32-bit). The output cards only have 12-bit DAC's, so there is a large amount of information stored that is never used by the cards. Is there a way in Labview to store AO data in another, smaller datatype - such as a 16-bit integer. This would greatly reduce the memory requirements for my application.
I just figured out the answer to my own question. There isn't an option for binary in the AO Write vi, but if you go down to the AO Buffer Write vi (which is called by AO Write), you can select binary array.
Thanks for all your help.
Josh -
Need a single-precision/2-byte conversion tool
Any one have a utility to convert 4-byte single precision numbers to and from a 2-byte representation?
I only need 3 digits, with one fractional digit (-14.3, for example).
Thanks...At one time I thought I wanted to do this, but never got around to it. I did find this information useful, however.
http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf -
Convert a byte/Byte - HEX STRING ?
Hi ,
My Problem is , I want to convert a byte/Byte value to hex string. If there is any way to convert bytes to hex strings then please tell me.
please help me.Integer.toHexString(byteValue);
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html -
I would like to save the WMF file with proper dimensions as they are in the editor (my saved WMFs have the dimensions of my screen resolution). They come from a RichEdit.
Thanks.
Edit:
My goal is to convert the images that appear on a RichEdit to another format.
Here is the fragment of the RTF:
{\pict\wmetafile8\picw7407\pich9259\picwgoal4199\pichgoal5249
010009000003703e020000005a3e02000000050000000b0200000000050000000c022b24ef1c5a
ffffffffffffff030000000000
}\cf2\lang1033\b\f1\fs23\par
For each 2 chars in this string I converted it to hex and saved it through a memory stream. Then I opened it in Paint or GIMP and there is the image. I even can convert it to a PNG file through ImageMagick tool. But the dimensions are wrong. How to fix
this?
I am using Lazarus.
I could guess that the header is not OK, but how they can be opened by Paint and converted? So I guess the dimensions info is wrong in the header. In GIMP even the dimensions are right, here a link to the GIMP's dialogbox confirmation with the dimensions
it has encountered in the file ( http://s13.postimg.org/s536tgo9z/Metafile_in_GIMP.png ).
So the info is there, but is wrong. When I open the images in Paint, they are wrong. Microsoft Office Picture Manager can also open them correctly, but could not convert them so. I need to do it programmatically. TMetafile Delphi class could not open these
files as well in order to be converted. So I could only edit the bytes.
My RichEdit WMF data can not be accepted by ComputeAldusChecksum routine nor get a handle from SetWinMetaFileBits API call, which would convert it to an EMF format.
procedure TMetafile.ReadWMFStream(Stream: TStream; Length: Longint);
var
WMF: TMetafileHeader;
BitMem: Pointer;
MFP: TMetaFilePict;
begin
NewImage;
Stream.Read(WMF, SizeOf(WMF));
if (WMF.Key <> WMFKEY) or (ComputeAldusChecksum(WMF) <> WMF.CheckSum) then
raise EComponentError.Create('Invalid metafile.'); // <<<<<<<<<<<<<<< exception here
Dec(Length, SizeOf(WMF));
GetMem(Bitmem, Length);
with FImage do
try
Stream.Read(BitMem^, Length);
FImage.FInch := WMF.Inch;
if WMF.Inch = 0 then
WMF.Inch := 96;
FWidth := MulDiv(WMF.Box.Right - WMF.Box.Left,25400,WMF.Inch);
FHeight := MulDiv(WMF.Box.Bottom - WMF.Box.Top,25400,WMF.Inch);
with MFP do
begin
MM := MM_ANISOTROPIC;
xExt := 0;
yExt := 0;
hmf := 0;
end;
FHandle := SetWinMetaFileBits(Length, BitMem, 0, MFP);
if FHandle = 0 then
raise EComponentError.Create('Invalid metafile.'); // <<<<<<<<<<<<<< exception here
Enhanced := False;
finally
Freemem(BitMem, Length);
end;
end;Hi Antônio G,
Based on your description, I’m afraid that it is not the correct forum for this issue, since this forum is to discuss:
Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.
To make this issue clearly, would you mind letting us know more information about this issue? Which language are you using? Which kind of app are you developing?
Reference:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/a9e1857d-dd5b-443b-8633-397aea6e7b8c/help-on-properly-handling-wmf-mmanisotropic-image-in-rtf-file-when-extracted?forum=csharpgeneral
https://social.msdn.microsoft.com/Forums/vstudio/en-US/5b99d331-ef56-4d60-bf12-3e3b70783376/how-to-convert-a-hex-string-save-in-a-rtf-file-into-an-image-jpg-or-bmp?forum=csharpgeneral#a9219408-f73b-4e98-a9d8-7a1e0f20cdd9
Maybe you could select the language development forum for this kind of issue. If not, please let me know more information about it, I will help you find a more appropriate forum.
Best Regards,
Jack
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How could I choose some bytes from HEX string and then convert it to a decimal value?
Hi I am working with an OMRON E5EN temperature controller using VISA serial to get data, I send the Read from Variable Area command and get this string in hexa 0230 3130 3030 3030 3130 3130 3030 3030 3030 3030 3041 3203 71 or .01000001010000000000A2.q in ASCII this string means:
02 STX
3031 3030 Node and subadress
3030 End Code Normal Completion
3031 3031 Command Read from Variable Area
3030 3030 respt code Normal completion
3030 3030 3030 4132 Hexadecimal A2 = 162 (this is the temperature data that I want to show in decimal)
03 ETX
71 Block Check Character
I want to choose the eight bytes for the temperature data and convert it to a decimal number. I have seen the examples to convert a Hexa string to decimal but I do not know how to choose the specifics bytes that I need.
I have look for a driver but i didn´t find any. I am a beginner so please include especific topics for me to study in your answer.
Thanks
Carlos Fuentes Silva Queretaro MexicoIf the response always has the temperature starting with byte 15 and is always 8 bytes in length, you can use the String Subset function to get those bytes out of the string. Then use Hex String to Number to convert to a decimal number.
Well someone already beat me to the solution:
Message Edited by tbob on 01-04-2008 04:42 PM
- tbob
Inventor of the WORM Global
Attachments:
HexStr2Decimal.png 7 KB -
Writing to spread sheets with more than single precision
Hi everyone,
Im recording data by using the write to spread sheet VI in Labview 8,
it records single precision which is a problem for me as I require greater
precision.
Are there ways around this issue?
Thanks
Solved!
Go to Solution.What do you mean by this? Is it possible for you to post code which only shows what you are trying to explain?
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies -
Non-hex character in hex string after upgrade to Yosemite
Hi,
When I try to open some of my files I get an error: "Acrobat PDF File Format is having difficulties. Non-hex character in a hex string". I could open the files before.
The only thing I've done since I opened the file last was to upgrade to Yosemite. The error occurs on both my Mac Pro (late 2013) and Mac Book Pro with Yosemite. Unfortunately, I have no access to a Mac with Mavericks and CS6 but I will try to fix one to verify that the file works there.
Affected files (Created in Illustrator CS6 on Mavericks):
services.ai
visual guidelines v.0.4.pdf
visual guidelines.ai
Tested steps:
Open previous versions of the same file from our repository
Update Illustrator CS6 to latest version
Download Illustrator CC
Tried to Place the file into another file (same error)
Tried to repair file Enable content recovery mode | Illustrator CS2-CS5Hi svepdesigncenter,
How you are accessing those files from your repository?
There might be chances of getting files corrupted when transferring.
File may have been sent as ascii when it should have been sent as binary or vice versa.
In 99% of transfers it's ALWAYS safest to zip an AI or eps file before sending it anywhere.
Regards,
Sumit Singh
Maybe you are looking for
-
I've moved my iTunes to a new PC, but it will only play the first 7 mins of each audiobook
I've recently bought a new PC, and have transferred by iTunes library over using an external hard drive. All of the music is fine, but the majority of the audiobooks won't transfer properly - when I play them, they cut out at 7 mins 31 secs. I've got
-
I have a samsung lcd and it will power on but the screen remains black. Is this worth fixing or should I throw it out?
-
Full screen caller image not coming in nokia 5800
Hi, Previously i was getting full screen caller image in my nokia 5800 but from last week i am getting thumbnail size small image during the call. Please let me know how to fix this.
-
I want to set up icloud, but I am a little confused. My wife and I each have an iPhone and Ipad, but only one Mac, what would be the best way to set this up, I would like to share our calendar and adress book. I do have all the devices working using
-
Can't backup iPhoto library to external drive
I've tried three times today to backup my iPhoto libray to an external hard drive. The file is 22.2 GB in size. Using Firewire the transfer is supposed to take about 45 mninutes. Each time at around :25-:30 it suddenly stops and I get an error mess