Bro convert hex string to int - bro

I am using bro to read bytes directly of the payload of a packet.
I have a string value "\x10" and I want to get the decimal value of off that.
I know that bro support directly printing hex to decimal:
print 0x10;
Question is, how do I convert that string similarly to its integer version?

The best you can do is strip off the "\x" portion, and run it through 2 BIFs:
bytestring_to_count(hexstr_to_bytestring("10"));

Related

Visual Basic "Format" function turning Hex values that end with A into a time

I have inherited some code and am very new to VB.
The code is basically being fed decimal values, these are being converted into the Hex equivalent and (I think) the Format function is being used to make sure only 2 characters (i.e. a byte) are being used in another string.
The problem is this, when the Format function encounters a Hex value that Ends in an 'A', it seems to convert the string into a time format of some sort.
Example:
"4A" converts to 04:00:00
"7A" converts to 07:00:00
Here's the relevant code snippet:
Format("4A")
In the actual code I'd get a "00", as the function has the following optional additions:
Format("0A","00")
I'm assuming the "A" is some special character.
Anybody have an idea around this quirk? Thanks in advance!
A is being interpreted as AM just as P would be PM and output 16:00.
Format() is likely not the correct thing to use here, it would only pad as you want it to if the input were a number.
Better to pad after you convert the base:
hexa = Hex$(i)
If (i < 16) Then hexa = "0" & hexa

Labview converting hexformatted string to ascii

In labview I am trying to convert a hex string to ascii format. For example if I have a hexstring like: 09124E4F21CD0024FFFFFFFFFFFFFFFF the ascii version of this is : NO!Í or basically a bunch of illegible symbols. I tried using the labview functions of converting hexstring to number but they didn't work. How would I convert the ascii part to hexformatted ascii?
Hexadecimal String to Number works fine, but only for a hex string that represents a number that can be stored as a numeric data type:
If the input string represents a number outside the range of the
representation of number, number is set to the maximum value for that
data type.
Your example input is 128 bits long whereas the longest integer data type in current LabVIEW is 64 bits.
You can use this function, but you need to convert the input one byte at a time:
Create a While Loop and add a shift register. Initialise the shift register with your input string.
Inside the loop, wire the string from the shift register to the string input of a Search/Split String function
Wire a numeric constant of 2 to the offset input - i.e. split the string into the first two characters, and the rest
Wire the match + rest of string output to the right-hand shift register terminal
Wire the substring before match output to a Hexadecimal String to Number function
Wire the default input of this function to a numeric constant with value 0 and type U8
Wire the output of this function to the right-hand side of the While loop and make the terminal indexing (via right-click)
Use an Empty String/Path? function to exit the While loop when the string being passed back into the shift register is empty.
The output from the indexing terminal you created will now be a U8 (byte) array containing the data converted from the input string. If you want it in string form you can convert it using Byte Array to String.
This assumes that your input string is always a multiple of 2 characters in length. If you need it to handle an input such as "3F2" you'll need to check for this and do something to the input (I'll let you figure out what) before passing it into your loop.

Convert 4 Byte String Array of Hex to Decimal

I am trying to convert a string of 4 bytes in a string to an integer number in LabView, currently I am using the string subset to break apart my string and then storing it into a String Indicator on the front panel, however, I need to convert that string to an int so I can show the decimal value as well as convert it from inches to mm. Here is what I'm doing now:
I've tried converting to double using the convert string to double functions as well as I've tried splitting it up using the index array...can't quite seem to get an int out ever. Thanks!
Do as Ton Plomp said and use the Scan From String block. However, in yours, you don't want to separate with commas and with spaces. Just do:
%x%x%x%x
And that should do it for ya. Don't forget to pull the scan down so you have 4 outputs.
You can use Scan from string with the following format string:
%x
You can expand the scan from string to scan multiple items at once.

Binary file output for fixed length string

I am trying to write a binary file which also has a string which i want to have as fixed length in vb.net. I tried lset, padleft in debug, the value returned is correct but in the output file, the first character before the string is the fixed length i specified. why does the binary writer write the additional char ?
I found out that if if you don't want or need the length byte you can call Write with a Char [] array instead of a String

Hexadecimal numbers vs. hexadecimal enocding (with base64 as well)

Encoding with hexadecimal numbers seems to be different from using hexadecimals to represent numbers. For example, then hex number 0x40 to me should be equal to 64, or BA_{64}, but when I put it through this hex to base64 converter, I get the output: QA== which to me is equal to some number times 64. Why is this?
Also when I check the integer value of the hex string deadbeef I get 3735928559, but when I check it other places I get: 222 173 190 239. Why is this?
Addendum: So I guess it is because it is easier to break the number into bit chunks than treat it as a whole number when encoding? That is pretty confusing to me but I guess I get it.
You may wish to read this:
http://en.wikipedia.org/wiki/Base64
In summary, base64 specifies a specific encoding, which involves using different values for letters than their ASCII encoding.
For the second part, one source is treating the entire string as a 32 bit integer, and the other is dividing it into bytes and giving the value of each byte.