I wonder if what is needed here is just null-terminated strings.

-Bruno


On Mon, Mar 13, 2023 at 1:28 PM Kurtis Rader <kra...@skepticism.us> wrote:

> On Mon, Mar 13, 2023 at 9:41 AM Van Fury <furyva...@gmail.com> wrote:
>
>> Relating to my previous question, I have been reading but it is still not
>> clear to me what raw binary is, how is it different from
>> text formatted binary (fmt.Sprintf("%b", s1s2Byte))?
>> In my problem above I need to encode s1+s2 to raw binary before sending
>> the result to the server
>> which then decodes the raw binary back to s1+s2.
>>
>
> At this point I think we are looking at an XY problem
> <https://xyproblem.info/>. Your s1 and s2 string variables are sequences
> of raw bytes; i.e., "raw binary". It would probably help us help you if you
> more fully described the problem rather than focusing on your solution.
> Especially since your solution doesn't work. In fact, your solution can't
> work without imposing more structure on the encoding to make it possible
> for the recipient to know where s1 ends and s2 begins.
>
> On Mon, Mar 13, 2023 at 5:39 PM Van Fury <furyva...@gmail.com> wrote:
>>
>>> Do you mean encoding should be
>>> rawdata := fmt.Print("%016d%s%s", len(s1), s1,s2)
>>> or
>>> rawdata := fmt.Printf("%016d%s%s", len(s1), s1,s2)
>>>
>>>
>>>
>>> On Monday, March 13, 2023 at 4:36:50 PM UTC+2 Alex Howarth wrote:
>>>
>>>> You might be looking for strconv.ParseUint()
>>>> https://pkg.go.dev/strconv#ParseUint
>>>>
>>>> https://go.dev/play/p/qAO9LfLD41D
>>>>
>>>> On Mon, 13 Mar 2023 at 07:24, Van Fury <fury...@gmail.com> wrote:
>>>>
>>>>>
>>>>> Sorry I did not frame my question properly but what I would like to do
>>>>> is to
>>>>> encode concatenated s1 and s2 into raw binary and then decode the raw
>>>>> binary
>>>>> back to s1 and s2.
>>>>>
>>>>>
>>>>> On Friday, March 10, 2023 at 11:36:09 PM UTC+2 Alex Howarth wrote:
>>>>>
>>>>>> If s1 and s2 are a fixed length then you can just slice up the
>>>>>> decoded string based on the lengths. If they are of a variable length,
>>>>>> you'll need a separator in the input string to later split on when 
>>>>>> decoded
>>>>>> (s3 := s1 + ":" + s2 etc)?
>>>>>>
>>>>>> On Fri, 10 Mar 2023 at 10:33, Van Fury <fury...@gmail.com> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have two hexadecimal string values and would like to concatenate
>>>>>>> the two strings and
>>>>>>>
>>>>>>>    1. encode the result to binary
>>>>>>>    2. decode the resulting binary back to hexadecimal string
>>>>>>>
>>>>>>> I did the following but I was finding it difficult to decode the
>>>>>>> result back. I ignore error check in this case.
>>>>>>>
>>>>>>> What i did so far:
>>>>>>>
>>>>>>> s1 := "1d28ed66824aa2593e1f2a4cf740343f"
>>>>>>>
>>>>>>> s2 := "dee2bd5dde763885944bc9d65419"
>>>>>>>
>>>>>>> s3 := s1 + s2
>>>>>>>
>>>>>>> s1s2Byte, _ := hex.DecodeString(s3)
>>>>>>>
>>>>>>> randAutnBin := fmt.Sprintf("%b", s1s2Byte)
>>>>>>>
>>>>>>> result:
>>>>>>>
>>>>>>> [11101 101000 11101101 1100110 10000010 1001010 10100010 1011001
>>>>>>> 111110 11111 101010 1001100 11110111 1000000 110100 111111 11011110
>>>>>>> 11100010 10111101 1011101 11011110 1110110 111000 10000101 10010100 
>>>>>>> 1001011
>>>>>>> 11001001 11010110 1010100 11001]
>>>>>>>
>>>>>>> I would like to decode the binary result back the hexadecimal string
>>>>>>> to get s1 and s2.
>>>>>>>
>>>>>>> Any help?
>>>>>>>
>>>>>>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_oDA%3DEB4My7NJ0W_%3D0UtTTJeDeGqRotiK%3DSTKTRv4Cxw%40mail.gmail.com
> <https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_oDA%3DEB4My7NJ0W_%3D0UtTTJeDeGqRotiK%3DSTKTRv4Cxw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEd86Tw0_fsEZ38Cex9e2Wfmdf3wmFxcP3KuqmxTS%3DUFPwVWRQ%40mail.gmail.com.

Reply via email to