Try this: l=7 x=6 set(itertools.permutations([1]*x + [0]*(l-x))) results in: {(0, 1, 1, 1, 1, 1, 1), (1, 0, 1, 1, 1, 1, 1), (1, 1, 0, 1, 1, 1, 1), (1, 1, 1, 0, 1, 1, 1), (1, 1, 1, 1, 0, 1, 1), (1, 1, 1, 1, 1, 0,...
The first parameter of fwrite expects a pointer. Lines such as the following: fwrite(L->PAGES, sizeof(int), 1, arq); Should be written as follows: fwrite(&(L->PAGES), sizeof(int), 1, arq); Sames goes for YEAR and PRICE members of that struct fwrite(&(L->YEAR), sizeof(int), 1, arq); ... fwrite(&(L->PRICE), sizeof(float), 1, arq); Note, you don't need to...
arrays,matlab,binary,pattern-matching
Something like this should do the job: b = diff(a); % (assuming 'a' is a vector) oneFromZero = find(b == 1) + 1; % vector of indices of a '1' preceded by a '0' zeroFromOne = find(b == -1) + 1; % vector of indices of a '0' preceded by...
c,binary,double,bit-manipulation,arc4random
When I print the binary representations of i and *(&i+1) and compare them to the binary representation of d, d is composed by appending *(&i+1) and i. So *(&i+1) comes first?! Why is this the case? the actual ordering of the bytes depends upon the 'Endian-ness' of the underlying...
c++,arrays,string,binary,bitset
Assuming you want to start at ASCII code 64, and that 'a' (or 'A') is simply 000001 in that case, then you can simply do c1 = static_cast<char>(std::bitset<6>(arr[0]).to_ulong() + 64); // 'A' in decimal is 65, in binary is 0b01000001. 'a' in decimal is 97, in binary is 0b01100001. In...
printf is function wide supported function. C, cpp, php, python, bash... so classic implementation in C would be: FILE *fp =fopen('binfilename.bin', 'w'); fprintf(fp, "\x45\x67\x89"); fclose(fp); all other languages have similar usage. you mention bash, and i think there is no simpler way than bash itself: printf "\x45\x67\x89" > binfilename.bin Every...
You are on a little-endian platform, so your array is equivalent to the 32-bit integer 0x00000019, which, as an IEEE single precision floating-point number, is approximately 3.5 * 10-44.
Calling to_i on a file handle returns the low-level identifier for it, a singular number, nothing more. If you want to operate on the bytes themselves: File.open(input_file, 'rb') do |f| File.open(output_file, 'wb') do |o| o.write( f.read.bytes.collect do |byte| byte ^ xor_value end.pack("C*") ) end end The key here is to...
matlab,matrix,binary,binary-matrix,binary-image
Here is one alternative without bin2dec or dec2bin conversion out = arrayfun(@(x,y) strcat(num2str(x),num2str(y)),A1,A2,'Uni',0); Input: A1 = [1 0 0; 0 1 1; 1 0 1]; A2 = [0 1 0; 1 1 0; 0 0 1]; output: >> out out = '10' '01' '00' '01' '11' '10' '10' '00' '11'...
c++,binary,decimal,floating-point-precision,significant-digits
what is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance? The most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance (for single-precision floating-point numbers or 24-bits) is...
I think he meant: (num // 10) + (num % 10) With num // 10 you perform an integer division with 10. But this is the first digit. With num % 10 you get the remainder of the division, which is the second digit. For example: >>> 67 // 10...
matlab,matrix,binary,integer,mathematical-optimization
The correct syntax for bintprog is X = bintprog(f,A,b,Aeq,beq). If you don't have f (which means you just want any feasible point), you can set it to []. However, for the others, your syntax is slightly wrong. I am assuming that the + in your constraints is actually a *...
The biggest issue I see is that there's more to unpacking binary data than just knowing "short" or "long". For numeric values, you need to specify whether or not the byte data is in little or big endian order. You also need to know whether or not you're dealing with...
Ok, it looks like you actually are reversing parts of an IP packet based on the diagram. This diagram is based on 32-bit words, with each bit being shown as the small 'ticks' along the horizontal ruler looking thing at the top. Bytes are shown as the big 'ticks' on...
In addition to @Amit's response, this will work as well: int i1=10, i2=11, i3=4, i4=3; char result[5]; sprintf(result,"%x%x%x%x\n", i1,i2,i3,i4); This eliminates the bit shifting but produces the same result because of the nature of binary to hex conversions....
You can use the modules erl_scan and erl_parse, as in this answer. Since erl_scan:string requires a string, not a binary, you have to convert the value with binary_to_list first: > {ok, Scanned, _} = erl_scan:string(binary_to_list(<<"{1,2}">>)). {ok,[{'{',1},{integer,1,1},{',',1},{integer,1,2},{'}',1}],1} Then, you'd use erl_parse:parse_term to get the actual term. However, this function expects the...
What you did was pretty good. I changed it up a little bit to match the complete number and accommodate all possible cases: ((?:0*1){3,}0*) See an example here. This is, of course assuming you only have binary numbers. If not, feel free to change up the 0 to [02-9] to...
java,binary,integer,number-formatting
The number that you're trying to parse is bigger than 2^31-1 (max integer), use Long instead: String s = "11111111110000011101110111011000"; System.out.println(Long.parseLong(s, 2)); // 4,290,895,320 If you want to see what's the maximum value of an Integer you can do: System.out.println(Integer.MAX_VALUE); // 2,147,483,647 Responding your UPDATE section, if you don't mind...
binary,numbers,32-bit,ieee-754,ieee
Since i will assume you already know the Standard we can convert as following , Convert your number to base 2 1011.01000 Shift this binary number 1.01101000 2**3 (shifted by 3) add exponent 127+3=130 convert 130 to binary format 10000010 And so we have sign * 2^exponent * mantissa Sign...
It's not that hard. Of course there's a system to it - else no program could print or edit names like Ñáñez... The upper bits in each byte indicate what is the status of that byte: 1) if bit 7 is 0, then it's just ASCII (*0*1110111 = w) 2)...
What does it have to do with memory? It has to do with memory addressing, which is done using binary numbers as well. On a very high level, a typical memory chip works like this: it has pins of three types - address pins, data pins, and control pins....
The constructor for BitArray(bool[]) accepts the values in index order - and then CopyTo uses them in the traditional significance (so bitArray[0] is the least significant bit) - so your true, true, false, false ends up meaning 0011 in binary, not 1100. It's not ignoring the last two bits -...
python,while-loop,binary,floating-point,decimal
I don't think this code is written all that well, but here's a rough idea. The first while loop: while ((2**p)*x)%1 != 0: ... is figuring out how many places in binary to the right of the decimal point will the result be. To use a familiar analogy let's work...
c,binary,reverse-engineering,x86-64,elf
They are stripped in the output. Use -W [[email protected] osboxes]# readelf -sW /usr/sbin/httpd | grep get_open 540: 000000000027bfc8 8 OBJECT GLOBAL DEFAULT 24 ap_hack_ap_hook_get_open_htaccess 1039: 000000000027c040 8 OBJECT GLOBAL DEFAULT 24 ap_hack_ap_hook_get_open_logs 1072: 000000000003ffb0 8 FUNC GLOBAL DEFAULT 13 ap_hook_get_open_logs 1451: 00000000000404d0 8 FUNC GLOBAL DEFAULT 13 ap_hook_get_open_htaccess ...
This is undefined behavior. The standard merely states that The class template bitset<N> describes an object that can store a sequence consisting of a fixed number of bits, N. It says nothing about the layout of this class internally. There is no guarantee that sizeof(bitset<8>) is 1. On my implementation,...
Two's complement is probably one of the more straightforward operations on binary numbers. In short, you'll want to take the following actions to convert a decimal number into two's complement form: Write down the binary representation of the positive version of your number. In this case, 25 should be represented...
You don't need reinterpret_cast here, the static_cast is sufficient. Your code doesn't work with pointers so there is no aliasing issue. Conclusion: There is nothing wrong in this approach. BTW: Your code really compiles to the "neg" instruction, at least on Intel platforms. ;-) Update: The C++ language specification...
You have it backwards. It is the binary number 1 shifted left by 'x' spots. And that should make sense. If you want to check the 4th spot in the table, represented by 'f', you have to check that f & 10000!=0. You're right, shifting by one is very arbitrary...
c++,io,binary,fstream,blitzmax
Just follow in the same fashion: int num = 50; unsigned char x = 9; float t = 9.0; ofstream file("file.bin", ios::binary); file.write(reinterpret_cast<const char *>(&num), sizeof(num)); file.write(reinterpret_cast<const char *>(&x), sizeof(x)); file.write(reinterpret_cast<const char *>(&t), sizeof(t)); file.close (); return 0; Some more info on reading. But beware of portability issues when doing...
Is this Go code correct and portable It is correct, as long as you work with unsigned integers of 64-bit width. Portability in this case is provided by the sync/atomic packages to the architectures supported by the Go compiler. Note, however, that not all architectures support "true" atomic operations...
java,string,algorithm,parsing,binary
There is nothing wrong with your code except int type can only hold so much. Int holds 4 bytes that is 8bitsx4 = 32 bits with the first one reserved for sign, negative if 1 and positive if 0. Try using long int which holds 64 bits: public static long...
c,binary,opcode,objdump,disassembler
As Hans noted, the memory location has nothing to do with it. What you need to do is find where the byte (or bytes) are located in the file. For this a really good disassembler (this would be IDA-Pro) makes you live very easy. Sadly, there is a steep price...
You can open the file with a standard python file open, then seek to skip the header, then pass in the file object to fromfile. Something like this: import numpy as np import os dtype = np.dtype([ ("time", np.float32), ("PosX", np.float32), ("PosY", np.float32), ("Alt", np.float32), ("Qx", np.float32), ("Qy", np.float32), ("Qz",...
math,model,binary,constraints,cplex
From memory, the sum(q in papers) only applies to the immediate following term. Try putting the two separate parts in parentheses, like: forall(p in papers) sum (q in papers) ( y[p][q] + y[q][p] ) <= 1; ...
1. Your date is declared as: char date[19]; 2. Your date format is exactly 19-characters long: 15/11/2013 12:16:56 3. And you print it this way: cout<<head.date Shortly speaking, you try to print fixed char[] using its address, which means, that it will be interpreted as null-terminated c-string. Is it null-terminated?...
In this simple case perhaps this suffices: result = array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3] For example: array = [1, 2, 3, 4] result = array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3] print result Prints this: 16909060...
I found a more simple solution : request(req.url).pipe(res); This pipe the original response from distant Web Service directly to my response ! I got the correct file and so regardless of filetype...
Java's default behaviour is to write files (and any other data streamed to IO) in big endian. C++ writes files in native format. On a standard x86-derived PC native is little endian, so for 0.5 you get: 0x00 00 00 3f in C++ and 0x3f 00 00 00 in Java....
There is a 1 byte datatype in (almost) every programming language. It is the character. It is actually the definition of a byte, that it can hold a default character. There is also a 1-byte (strictly speaking 1-octet) integer type in Fortran, accessible as integer(int8) where int8 is a constant...
java,android,sockets,http,binary
when you use BufferedReader you'll get the input into String format..so better way to use InputStream... here is sample code to achieve this. InputStream in = socket.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] read = new byte[1024]; int len; while((len = in.read(read)) > -1) { baos.write(read, 0, len); } //...
c,arrays,image,binary,unsigned
The problem is that you are trying to get the size of art, which is a pointer. It has fixed size. Size should be computed as width*height: printf("Size of Array: %d x %d (%d)\n", width, height, width*height); You declared art as an unsigned char, but you are assigning it a...
Assuming the layout is a static binary structure that can be described by a simple struct pattern, and the file is just that structure repeated over and over again, then yes, "traverse the whole binary unpacking a certain number of bytes at a time" is exactly what you'd do. For...
The bsearch() function is pretty flexible, because you can pass a pointer to any kind of array. Changing the base parameter to const void **base would imply that you could only use bsearch() on arrays of pointers. If you are searching an array of int, then you should certainly pass...
It seems I'm not making the right approach, keep getting -1 which means end of file. Exactly so. It means end of file. You should only get it once. You keep getting because you aren't testing for it and breaking out of the loop when you get it. Instead...
You could use itertools.product: from itertools import product n = 3 # generate product in reverse lexicographic order bin_str = [''.join(p) for p in product('10', repeat=n)] # ['111', '110', '101', '100', '011', '010', '001', '000'] # sort by number of ones bin_str.sort(key=lambda s: s.count('1')) # ['000', '100', '010', '001', '110',...
php,mysql,sql-server,binary,hex
Put the binary files on disk. There is no reason to keep them in the database. What you might want to do is read the files with a document reader and index their content. Put that content in the database so you can easily search the files....
Try using a diag call in combination with ones. For your case, you have a 10 x 10 identity matrix and want to shift the diagonal to the right by 1. >> n = 10; >> shift = 1; >> A = diag(ones(n-abs(shift),1),shift) A = 0 1 0 0 0...
DF <- read.table(text = " ID Elevation Year Individual.code 1 Area1 11.0 2009 AA 2 Area1 11.0 2009 AB 3 Area3 79.5 2009 AA 4 Area3 79.5 2009 AC 5 Area3 79.5 2009 AD 6 Area5 57.5 2010 AE 7 Area5 57.5 2010 AB 8 Area7 975.0 2011 AA 9...
The pymongo driver already has methods for importing strings as binary. Following with this example: import pymongo import bson.binary from pymonngo import MongoClient from bson.binary import Binary client = MongoClient() db = client.test db.btest.insert({ "bindata": Binary("Hello",0) }) db.btest.find_one() Which gives you: {u'_id': ObjectId('5582b33c268e1505371a5477'), u'bindata': Binary('Hello', 0)} Or from the mongo...
I found answer for this question in using another encoding, and writing bytes: file = open('file.bin','wb') cur = 0 while cur < len(code): c = int(code[cur:cur+8], 2) file.write(bytes(chr(c), 'iso8859-1')) cur += 8 I wrote string with 0 and 1: 000101101100000000010010110000010011000000010010001000100000000000010111110000110100001100010001 And if i open file with notepad I will see...
swift,binary,type-conversion,unsigned-integer
One of the fundamental principles of Swift is that is does not implicitly convert between types. let u: UInt8 = 0b1 let i: Int = 0b10 i | Int(u) forces you to think about the necessary conversions and what type the result should have, so that is the correct solution...
n is not "a decimal". I think you have a misconception of what numbers are, based on the default output representation used by IOStreams. They are numbers. Not decimal strings, binary strings, hexadecimal strings, octal strings, base-64 strings, or any kind of strings. But numbers. The way you choose to...
To convert the bits of a double to a String, you can use Double.doubleToLongBits, which creates a long with the same bits as the double, followed by Long.toBinaryString to convert it to a String with the bits as characters. double test = 0.5; long doubleBits = Double.doubleToLongBits(test); String doubleBitsStr =...
You don't need an array with the powers of two - the computer already knows them and you can use 1<<k to get the k-th power of two. However you don't need that either. Here is a short function to parse int from a char array that is the binary...
I approached the problem the following way: function ok = lets(file_name) file = memmapfile( file_name, 'writable', false ); lowercase = [65:90]; uppercase = [97:122]; data = file.Data; ok = sum(histc(data,lowercase)+histc(data,uppercase)); end I mapped the file to memory using the memmapfile function and compared the data with the character encodings from...
c++,binary,coding-style,constants,code-readability
You can use the shift left operator: if (buffer_length == 1 << 12){ } ...
Numbers in C/C++ are stored in binary so there is no need to "convert" them. You can use any C/C++ unsigned integral type you want to to store a 3 bit number so, for example, storing them in std::vector<unsigned char> would work fine. Along this line, rather than storing the...
see: Decimal to binary conversion in c # it should be: void tobinary(int bin) { string binary = Convert.ToString(bin, 2);} ...
First : move your picture around a little bit - line things up to make it easier The first one on the top line is above the 2nd '1' in 1001 1 * 101 is 101, so subtract 101 from 1001, resulting in 11 Then since 100 is less <...
perl,binary,type-conversion,decimal
You can use Math::BigInt. Please note, that input to these functions should be strings. use Math::BigInt; sub bin2dec { my $bin = shift; return Math::BigInt->new("0b$bin"); } sub dec2bin { my $dec = shift; my $i = Math::BigInt->new($dec); return substr($i->as_bin(), 2); } print "Dec: " . bin2dec("111110001011111001010101000010011001000010101111001110000000000000000000000000000000000000000000") . "\n"; print "Bin:...
binary,arduino,arduino-uno,eeprom
you are sending binary numbers to the serial port and not converting them to ascii, do this small change in your setup code by converting the binary numbers to ascii, char my_buffer_ax[10]; char my_buffer[200]; memset(my_buffer, 0, 200); strcat(my_buffer, "PO: "); //Set address pins to output for (int i=0; i <...
linux,terminal,binary,buffer,monitoring
I don't know which distribution you're using, but check to see whether you have, or can install, most. From the manpage: OPTIONS -b Binary mode. Use this switch when you want to view files containing 8 bit characters. most will display the file 16 bytes per line in hexadecimal notation....
c,binary,compression,decompression
Nice try, with just few corrections. You have to store a mark that will give you a clue how long was original value so you can decompress it back. Sure thing, there is nothing new under the moon so you can reuse such thing as VarInt: https://developers.google.com/protocol-buffers/docs/encoding#varints It's wide-spread practice...
haskell,recursion,binary,calculator
Something like binary2 :: Int -> [Int] binary2 x | x > 0 = binary x | otherwise = [] binary :: Int -> [Int] binary x | x `mod` 2 > 0 = binary2 (x `div` 2) ++ [1] | otherwise = binary2 (x `div` 2) ++ [0] So...
125 + 10 = 135. This is above 127, hence the addition overflows and the end result is 135 - 256 = - 121.
First of all INT means interrupt and has nothing to do with int data type. Each INT represents a functions family, where usually AH represents the function number. For example : INT 0x10 is used for screen manipulation AH=0x00 -> set video mode AX=0x1003 -> Set Blinking mode AH=0x13 ->...
Your data doesn't conform to the standard you've specified. Either contact your data supplier and have them fix their bug, or be more generous about your definition of "space". If you want to accept that data, you could, for example, do this: field[0].strip(' \t\n\x00') or, with more limited acceptance: field[0].strip().rstrip('\x00')...
This might do the trick: public static void Main() { byte[] buf = new byte[] { 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; byte result = 0; foreach(var b in buf.Reverse()) { result <<= 1; if(b == 0xFF) result |= 1; } Console.WriteLine(result); } ...
As @martineau mentioned, what you're seeing is C struct packing. The compiler adds padding between non-word size members to optimize memory access. You can disable this with certain #pragma directives. For Visual C, the syntax is #pragma pack(1) as explained in MSDN. In the following example I also use push...
In 4 bit 2'scomplement -2 is 1110 and +3 is 0011 so 11110 carry 1110 -2 +0011 +3 ---- 10001 which is 0001 or simply 1 ignoring the carry in bit 5 Stepping through the process from the right to the left: 1 + 0 results in 1 with no...
binary,floating-point,decimal,floating-point-precision,significant-digits
The precision is fixed, which is exactly 53 binary digits for double-precision (or 52 if we exclude the implicit leading 1). This comes out to about 15 decimal digits. The OP asked me to elaborate on why having exactly 53 binary digits means "about" 15 decimal digits. To understand this...
From BufferedInputStream.getInIfOpen() [Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.][quoted under fair-use]: private InputStream getInIfOpen() throws IOException { InputStream input = in; if (input == null) throw new IOException("Stream closed"); return input; } Very strange code. It should throw a NullPointerException. Possibly it is overloading null to also...
Logic wise. Get the even bits by anding with AAAAAAAA Then right shift that, to give N1er2 Get the odd bits by Anding with 55555555 to give N1o The result would be N1er2 Ored with N1o...
It's true that 9223372036854775808 becomes -9223372036854775808, but it's not so simple as just "integers wrap around". Here are a few more mappings (found by experimentation): 9223372036854775809 → still -9223372036854775808 (not -9223372036854775807) 9223372036854775810 → still -9223372036854775808 (not -9223372036854775806) So you might think that numbers outside the int range all get mapped...
php,replace,binary,hex,preg-replace
If the string is at fixed position, you can write data directly: $position=hexdec("00010edb"); // You have to pre-calculate it once $data="some data"; // Replacement if ($f=fopen("your_file", "r+")) { fseek($f, $position); fwrite($f, $data); fclose($f); } else { echo "Can't open file"; } ...
Instead of while (divisor <= dividend) { // this will not work with UINT_MAX divisor <<= 1; current <<= 1; } divisor >>= 1; current >>= 1; try unsigned k = 1 << (sizeof(unsigned) * 8 - 1); while (((divisor & k) == 0) && ((divisor << 1) <= dividend))...
You need to prefix your binary numbers with 0b: """Sistema de Cifrado Vernam""" #alfabeto alfabeto = {"a":0b00011,"b":0b11001,"c":0b01110,"d":0b01001,"e":0b00001,"f":0b01101,"g":0b11010,"h":0b10100,"i":0b00110,"j":0b01011,"k":0b01111,"l":0b10010,"m":0b11100, "n":0b01100,"o":0b11000,"q":0b10111,"r":0b01010,"s":0b00101,"t":0b10000,"u":0b00111,"v":0b11110,"w":0b10011,"x":0b11101,"y":0b10101,"z":0b10001, "<":0b01000,"=":0b00010,"fdown":0b11111,"fup":0b11011," ":0b00100, "":0b00000} """Mensaje en texto plano""" #Susituir...
python,python-2.7,binary,procedure
You have to declare a procedure in Python as shown [here] (http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/functions.html) e.g. def bin2dec(number): your code...
c#,matlab,file,binary,floating-point
You can use BinaryWriter to write the data to a file very easily: foreach (var value in samples32array) { writer.Write(value); } Now BinaryWriter is guaranteed to use little-endian format, so in your Matlab call, you should specify a machinefmt value of l to explicitly read it in little-endian format too....
Basically you could do something like: int myPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; byte sequence[] = {B01001001,B00000001,B00000011}; void setup(){ for(int i = 0; i < 8; i++){ pinMode(myPins[i], OUTPUT); } } void loop(){ for(int i = 0; i < 3; i++){ turnOnOff(sequence[i]); delay(500); //just to see...
python,csv,binary,data-conversion,hexdump
As already mentioned, without knowing the binary protocol it will be difficult to guess the exact encoding that is being used. There may be special case logic that is not apparent in the given data. It would be useful to know the name of the 3rd party application or a...
c++,memory,memory-management,binary
Yes. Endianness only affects how bytes are stored in memory. The value of 0x10203040 is always 270544960 regardless of whether it's the first or last byte in memory that is the 0x10. To gratuitously borrow images from the Wikipedia article on Endianness, regardless of which of these layouts our system...
Just divide the number of bits by 4: >>> bits = "0000000000001010" >>> '{:0{}X}'.format(int(bits, 2), len(bits) // 4) '000A' ...
You cannot directly write objects to a file in this way, unless you have a POD-style data structures (e.g. just simple C data types or a struct/class thereof, no pointers, no C++ data types). In your case, Person has two std::string members, which itself contain pointers and other stuff, which...
c,algorithm,tree,binary,binary-tree
You should be doing something like: int total_depth(tree_t *tree, int accum) { if (tree == NULL) { return 0; } return accum + total_depth(tree->left, accum + 1) + total_depth(tree->right, accum + 1); } total_depth(root, 0); ...
java,arraylist,binary,unsafe,unchecked
This isn't an error, it's a warning, but, as you noted, you should probably fix it. The problem is that you're passing an unbound ArrayList, that, theoretically, can hold elements of any type, while you're only dealing with Integers. So, instead, you could declare your parameter as an ArrayList of...
Let's suppose that you are looking for variables with a certain value label attached. You can retrieve those variables using ds and pass their names to recode. . clear . set obs 2 obs was 0, now 2 . forval j = 1/5 { 2. gen y`j' = _n 3....
Executable files may be scripts (in which case you can read the text), or binaries (which are ELF formatted machine code). Your shell script is a script; git is an ELF binary. You can use the file command to see more detail. For example, on my nearest Linux system: $...
You don't need the second loop, try this: foreach ($orderKey as $key => $value) { $ordered[$key] = $arrayDump[$value]; } ...