Re: convert a char[4] (binary) to an unsigned long
Thanks for this suggestion. It works! Somewhere else in my script, I
have to convert an unsigned long to a char[4]. I tried to use memcpy to
create a LongtoChararr function, but i failed. I'm not very familiar
with memcpy. Can you help me again?
Hans wrote:[color=blue]
> Vincent skrev:
>[color=green]
> > Hi all,
> >
> > I want to convert a char[4] (binary) to an unsigned long. How can I do
> > this?
> >
> > Thanks,
> > Vincent[/color]
>
> Use memcpy:
>
> unsigned long ChararrToLong(c onst char * const src)
> {
> unsigned long dest;
> memcpy(&dest, src, sizeof(dest));
> return dest;
> }
>
>
> This may be what you want or not. If you depend on the chars being put
> in a specific order into the unsigned long, you might want to do some
> byte-swapping while copying.[/color]
Thanks for this suggestion. It works! Somewhere else in my script, I
have to convert an unsigned long to a char[4]. I tried to use memcpy to
create a LongtoChararr function, but i failed. I'm not very familiar
with memcpy. Can you help me again?
Hans wrote:[color=blue]
> Vincent skrev:
>[color=green]
> > Hi all,
> >
> > I want to convert a char[4] (binary) to an unsigned long. How can I do
> > this?
> >
> > Thanks,
> > Vincent[/color]
>
> Use memcpy:
>
> unsigned long ChararrToLong(c onst char * const src)
> {
> unsigned long dest;
> memcpy(&dest, src, sizeof(dest));
> return dest;
> }
>
>
> This may be what you want or not. If you depend on the chars being put
> in a specific order into the unsigned long, you might want to do some
> byte-swapping while copying.[/color]
Comment