Find the answer to your Linux question:
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?...
  1. #1
    Just 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?

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    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

  3. #3
    Just 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).

  4. #4
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    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

  5. #5
    Just 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?

  6. #6
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    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

  7. #7
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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:
    Code:
    alex@danu ~ $ read a; let a=$a; echo $a;
    0x61
    97
    The 'let' keyword forces arithmetic evaluation, so it turns the string '0x61' into the number, and prints it in decimal.

    A few more specifics might help on figuring this out.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...