How to generate a 32 bit big-endian number in the format 0x00000001 in erlangCounting in Erlang (how do I increment a variable?)How do you do modulo or remainder in Erlang?Speed comparison with Project Euler: C vs Python vs Erlang vs HaskellErlang bit indexingErlang Bit Syntax: How does it knows that it's 3 components?How to generate a random alphanumeric string with Erlang?How can I handle Account Number in erlang?Erlang basic general server debugger output interpretationRead 16 bit little-endian, then parse as a bitstring in erlangBit Syntax and Binary Representation in ErlangWhy does Erlang generate the same sequence of random number if applying the same seed?

How to properly understand branches of complex functions

I just entered the USA without passport control at Atlanta airport

Improve appearance of the table in Latex

Is there any proof that high saturation and contrast makes a picture more appealing in social media?

Why isn't it a compile-time error to return a nullptr as a std::string?

Can I enter the UK for 24 hours from a Schengen area, holding an Indian passport?

What are the pros and cons for the two possible "gear directions" when parking the car on a hill?

Is the continuity test limit resistance of a multimeter standard?

Counterfeit checks were created for my account. How does this type of fraud work?

What happened to Hopper's girlfriend in season one?

Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?

Umlaut character order when sorting

Rejecting an offer after accepting it just 10 days from date of joining

Encounter design and XP thresholds

In Mistborn, why can metal in people's bodies be affected by Allomancy sometimes?

What triggered jesuits' ban on infinitesimals in 1632?

Print one file per line using echo

Explain why a line can never intersect a plane in exactly two points.

Novel in which alien (Martian?) is trapped on Earth in prehistory

Is "Busen" just the area between the breasts?

"Correct me if I'm wrong"

How many people are necessary to maintain modern civilisation?

Is it illegal to withhold someone's passport and green card in California?

Is there a difference between an NFC and RFID chip?



How to generate a 32 bit big-endian number in the format 0x00000001 in erlang


Counting in Erlang (how do I increment a variable?)How do you do modulo or remainder in Erlang?Speed comparison with Project Euler: C vs Python vs Erlang vs HaskellErlang bit indexingErlang Bit Syntax: How does it knows that it's 3 components?How to generate a random alphanumeric string with Erlang?How can I handle Account Number in erlang?Erlang basic general server debugger output interpretationRead 16 bit little-endian, then parse as a bitstring in erlangBit Syntax and Binary Representation in ErlangWhy does Erlang generate the same sequence of random number if applying the same seed?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I need to generate a variable which has the following properties -
32 bit, big-endian integer, initialized with 0x00000001 (I'm going to increment that number one by one). Is there a syntax in erlang for this?










share|improve this question




























    2















    I need to generate a variable which has the following properties -
    32 bit, big-endian integer, initialized with 0x00000001 (I'm going to increment that number one by one). Is there a syntax in erlang for this?










    share|improve this question
























      2












      2








      2








      I need to generate a variable which has the following properties -
      32 bit, big-endian integer, initialized with 0x00000001 (I'm going to increment that number one by one). Is there a syntax in erlang for this?










      share|improve this question














      I need to generate a variable which has the following properties -
      32 bit, big-endian integer, initialized with 0x00000001 (I'm going to increment that number one by one). Is there a syntax in erlang for this?







      erlang






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 7:08









      hasihasi

      175




      175






















          2 Answers
          2






          active

          oldest

          votes


















          4














          In Erlang, normally you'd keep such numbers as plain integers inside the program:



          X = 1.


          or equivalently, if you want to use a hexadecimal literal:



          X = 16#00000001.


          And when it's time to convert the number to a binary representation in order to send it somewhere else, use bit syntax:



          <<X:32/big>>


          This returns a binary containing four bytes:



          <<0,0,0,1>>


          (That's a 32-bit big-endian integer. In fact, big-endian is the default, so you could just write <<X:32>>. <<X:64/little>> would be a 64-bit little-endian integer.)



          On the other hand, if you just want to print the number in 0x00000001 format, use io:format with this format specifier:



          io:format("0x~8.16.0b~n", [X]).


          The 8 tells it to use a field width of 8 characters, the 16 tells it to use radix 16 (i.e. hexadecimal), and the 0 is the padding character, used for filling the number up to the field width.




          Note that incrementing a variable works differently in Erlang compared to other languages. Once a variable has been assigned a value, you can't change it, so you'd end up making a recursive call, passing the new value as an argument to the function. This answer has an example.






          share|improve this answer
































            0














            According to the documentation[1] the following snippet should generate a 32-bit signed integer in little endian.



            1> I = 258. 
            258
            2> B = <<I:4/little-signed-integer-unit:8>>.
            <<2,1,0,0>>


            And the following should produce big endian numbers:



            1> I = 258.
            258
            2> B = <<I:4/big-signed-integer-unit:8>>.
            <<0,0,1,2>>


            [1] http://erlang.org/doc/programming_examples/bit_syntax.html






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332733%2fhow-to-generate-a-32-bit-big-endian-number-in-the-format-0x00000001-in-erlang%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              In Erlang, normally you'd keep such numbers as plain integers inside the program:



              X = 1.


              or equivalently, if you want to use a hexadecimal literal:



              X = 16#00000001.


              And when it's time to convert the number to a binary representation in order to send it somewhere else, use bit syntax:



              <<X:32/big>>


              This returns a binary containing four bytes:



              <<0,0,0,1>>


              (That's a 32-bit big-endian integer. In fact, big-endian is the default, so you could just write <<X:32>>. <<X:64/little>> would be a 64-bit little-endian integer.)



              On the other hand, if you just want to print the number in 0x00000001 format, use io:format with this format specifier:



              io:format("0x~8.16.0b~n", [X]).


              The 8 tells it to use a field width of 8 characters, the 16 tells it to use radix 16 (i.e. hexadecimal), and the 0 is the padding character, used for filling the number up to the field width.




              Note that incrementing a variable works differently in Erlang compared to other languages. Once a variable has been assigned a value, you can't change it, so you'd end up making a recursive call, passing the new value as an argument to the function. This answer has an example.






              share|improve this answer





























                4














                In Erlang, normally you'd keep such numbers as plain integers inside the program:



                X = 1.


                or equivalently, if you want to use a hexadecimal literal:



                X = 16#00000001.


                And when it's time to convert the number to a binary representation in order to send it somewhere else, use bit syntax:



                <<X:32/big>>


                This returns a binary containing four bytes:



                <<0,0,0,1>>


                (That's a 32-bit big-endian integer. In fact, big-endian is the default, so you could just write <<X:32>>. <<X:64/little>> would be a 64-bit little-endian integer.)



                On the other hand, if you just want to print the number in 0x00000001 format, use io:format with this format specifier:



                io:format("0x~8.16.0b~n", [X]).


                The 8 tells it to use a field width of 8 characters, the 16 tells it to use radix 16 (i.e. hexadecimal), and the 0 is the padding character, used for filling the number up to the field width.




                Note that incrementing a variable works differently in Erlang compared to other languages. Once a variable has been assigned a value, you can't change it, so you'd end up making a recursive call, passing the new value as an argument to the function. This answer has an example.






                share|improve this answer



























                  4












                  4








                  4







                  In Erlang, normally you'd keep such numbers as plain integers inside the program:



                  X = 1.


                  or equivalently, if you want to use a hexadecimal literal:



                  X = 16#00000001.


                  And when it's time to convert the number to a binary representation in order to send it somewhere else, use bit syntax:



                  <<X:32/big>>


                  This returns a binary containing four bytes:



                  <<0,0,0,1>>


                  (That's a 32-bit big-endian integer. In fact, big-endian is the default, so you could just write <<X:32>>. <<X:64/little>> would be a 64-bit little-endian integer.)



                  On the other hand, if you just want to print the number in 0x00000001 format, use io:format with this format specifier:



                  io:format("0x~8.16.0b~n", [X]).


                  The 8 tells it to use a field width of 8 characters, the 16 tells it to use radix 16 (i.e. hexadecimal), and the 0 is the padding character, used for filling the number up to the field width.




                  Note that incrementing a variable works differently in Erlang compared to other languages. Once a variable has been assigned a value, you can't change it, so you'd end up making a recursive call, passing the new value as an argument to the function. This answer has an example.






                  share|improve this answer















                  In Erlang, normally you'd keep such numbers as plain integers inside the program:



                  X = 1.


                  or equivalently, if you want to use a hexadecimal literal:



                  X = 16#00000001.


                  And when it's time to convert the number to a binary representation in order to send it somewhere else, use bit syntax:



                  <<X:32/big>>


                  This returns a binary containing four bytes:



                  <<0,0,0,1>>


                  (That's a 32-bit big-endian integer. In fact, big-endian is the default, so you could just write <<X:32>>. <<X:64/little>> would be a 64-bit little-endian integer.)



                  On the other hand, if you just want to print the number in 0x00000001 format, use io:format with this format specifier:



                  io:format("0x~8.16.0b~n", [X]).


                  The 8 tells it to use a field width of 8 characters, the 16 tells it to use radix 16 (i.e. hexadecimal), and the 0 is the padding character, used for filling the number up to the field width.




                  Note that incrementing a variable works differently in Erlang compared to other languages. Once a variable has been assigned a value, you can't change it, so you'd end up making a recursive call, passing the new value as an argument to the function. This answer has an example.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 25 at 9:54

























                  answered Mar 25 at 9:36









                  legoscialegoscia

                  30.3k1187119




                  30.3k1187119























                      0














                      According to the documentation[1] the following snippet should generate a 32-bit signed integer in little endian.



                      1> I = 258. 
                      258
                      2> B = <<I:4/little-signed-integer-unit:8>>.
                      <<2,1,0,0>>


                      And the following should produce big endian numbers:



                      1> I = 258.
                      258
                      2> B = <<I:4/big-signed-integer-unit:8>>.
                      <<0,0,1,2>>


                      [1] http://erlang.org/doc/programming_examples/bit_syntax.html






                      share|improve this answer



























                        0














                        According to the documentation[1] the following snippet should generate a 32-bit signed integer in little endian.



                        1> I = 258. 
                        258
                        2> B = <<I:4/little-signed-integer-unit:8>>.
                        <<2,1,0,0>>


                        And the following should produce big endian numbers:



                        1> I = 258.
                        258
                        2> B = <<I:4/big-signed-integer-unit:8>>.
                        <<0,0,1,2>>


                        [1] http://erlang.org/doc/programming_examples/bit_syntax.html






                        share|improve this answer

























                          0












                          0








                          0







                          According to the documentation[1] the following snippet should generate a 32-bit signed integer in little endian.



                          1> I = 258. 
                          258
                          2> B = <<I:4/little-signed-integer-unit:8>>.
                          <<2,1,0,0>>


                          And the following should produce big endian numbers:



                          1> I = 258.
                          258
                          2> B = <<I:4/big-signed-integer-unit:8>>.
                          <<0,0,1,2>>


                          [1] http://erlang.org/doc/programming_examples/bit_syntax.html






                          share|improve this answer













                          According to the documentation[1] the following snippet should generate a 32-bit signed integer in little endian.



                          1> I = 258. 
                          258
                          2> B = <<I:4/little-signed-integer-unit:8>>.
                          <<2,1,0,0>>


                          And the following should produce big endian numbers:



                          1> I = 258.
                          258
                          2> B = <<I:4/big-signed-integer-unit:8>>.
                          <<0,0,1,2>>


                          [1] http://erlang.org/doc/programming_examples/bit_syntax.html







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 25 at 9:33









                          Christophe De TroyerChristophe De Troyer

                          1,48722139




                          1,48722139



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332733%2fhow-to-generate-a-32-bit-big-endian-number-in-the-format-0x00000001-in-erlang%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현