Results 1 to 7 of 7
Yeah, so that's a hex string (start of heading, start of text, end of text, enquiry). Is it possible to enter from the command line?...
- 05-04-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 6
is it possible to enter 0x01020305 via the command line?
Yeah, so that's a hex string (start of heading, start of text, end of text, enquiry). Is it possible to enter from the command line?
- 05-04-2007 #2
I don't see why not...what language are you using?
Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 05-04-2007 #3Just Joined!
- Join Date
- May 2007
- Posts
- 6
I'm using C. I have a simple 5 liner program with a gets(buff) where I want to enter that particular string using only the keyboard (not using another program to pipe over that string).
- 05-05-2007 #4
So let me get this straight: You want to enter 0x01020305 via standard input and parse it into an integer with the value 0x01020305?
Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 05-05-2007 #5Just Joined!
- Join Date
- May 2007
- Posts
- 6
I want to enter something from the command line that is equivalent to 0x01020305. There's no parsing. If I typed 'A', then that'd be 0x41. What string would I need to type to get 0x01020305?
- 05-05-2007 #6
Ohhhhh...I see. Well, you'll have to use some kind of escape sequence. They're usually in octal (ex. \033 is ESC), so look into terminal escape sequences.
Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 05-06-2007 #7
The easiest way to do this that I can think of (using C, at least), would be to simply give it as the decimal equivalent, then use the atoi function to convert the string to an int.
If you're using Bash, it seems that there's no super easy way to do this. The standard way would be $'\x##', but this only supports one or two digit hex numbers. However, something like this would work:
The 'let' keyword forces arithmetic evaluation, so it turns the string '0x61' into the number, and prints it in decimal.Code:alex@danu ~ $ read a; let a=$a; echo $a; 0x61 97
A few more specifics might help on figuring this out.DISTRO=Arch
Registered Linux User #388732


Reply With Quote