CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102

    Hi, hard problem for you pareshgh

    I got int with a signed number, and i want to split it to array of bytes, in little endian.

    any ideas?

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    I hope this will help you ( I wrote a console program and tested which will give you the result required,

    -------------
    // byte representation of a long number
    int a = 123456789; //111 01011011 11001101 00010101

    byte []b = new byte[4];

    b[0] = (byte)(a & 0xFF);
    b[1] = (byte)((a & 0xFF00) >>8);
    b[2] = (byte)((a & 0xFF0000) >> 16);
    b[3] = (byte) ((a & 0xFF000000) >>24);

    Console.WriteLine(b[0]);
    Console.WriteLine(b[1]);
    Console.WriteLine(b[2]);
    Console.WriteLine(b[3]);
    ----------------------

    b[0] is and'ing with 255 so get the first byte

    b[1] is and'ing only 2'nd byte and rest are zero'ed and then right shifted 8 bytes so as to get byte what's in it.
    and so on.

    Paresh

  3. #3
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102

    Talking you're a c# gosu

    great. thanks
    how you know all that stuff?

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    glad that you are happy. thanx
    but I am not a guru

  5. #5
    Join Date
    Oct 2002
    Location
    Torture chamber
    Posts
    132
    cool.
    end------------------------------
    Programmers aren't born, but are made from hardwork, effort and time.
    To be a good one, requires more effort and hardwork.
    Therefore N quality programmer = (N*hardwork)+(N*effort)+(N*time)

  6. #6
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    thanx a lot.

  7. #7
    Join Date
    Mar 2003
    Posts
    17
    bahahhahaha..
    You know what this thread sounds like..

    This thread sounds like a high school kid looking for someone to do his homeowork..


    **** some ppl can be so tricksy(LOTR)....


    I guess it beats renting a coder at rend a coder web site..

  8. #8
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    oh ! really
    LOL

  9. #9
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Hay you guys! Have you ever heart about the windows socket function like: ntohl()? It takes big indian long and conerts it into the little-indian on Intel processors...

    You can import them into the C# and use them...

    I know, it is just alternative and the paresh's solution works too...

    Martin

  10. #10
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    martin, as you are always informative,
    this is a good piece of information.

    thanx again,
    Paresh

  11. #11
    Join Date
    Mar 2003
    Posts
    17
    Originally posted by MartinL
    Hay you guys! Have you ever heart about the windows socket function like: ntohl()? It takes big indian long and conerts it into the little-indian on Intel processors...

    You can import them into the C# and use them...

    I know, it is just alternative and the paresh's solution works too...

    Martin
    I dont think underwater would get full marks for his assignment if he used an api function to answer the question...

  12. #12
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    hahaha
    lol
    he isn't underwater
    he is underwar. (with me )

    and yes, u r right. he won't get the full marks for his assignement. if i would be his professor i wdn't gave the internet access and then instructed to try on his own


    LOL again

    take it easy,
    Paresh

  13. #13
    Join Date
    Feb 2003
    Location
    Israel
    Posts
    102
    grrr

  14. #14
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Hm... If this is the point (to make things more difficult), I would recommed him to write the routine in LISP and use it in C#...

    Or even better, to use monolit microcomputer, write it in assembler and comunicatate with the monolit mc using COM port...

    Martin

  15. #15
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    this going crazy.. come on guys i am not gonna college LISP and theoritical programs...

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured