473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read a number of 128 bits

Please, I will like to Know how to read and store a variable of 128 bits and the split it in 16 variables of 8 bits each, and then create a matrix of 4x4 using each block of 8 bits, for instance:
input = 32 43 F6 A8 88 5A 30 8D 31 31 98 A2 E0 37 07 34;

the I need to create a matrix like this:


input_M = { {32 88 31 E0}, {43 5A 31 37}, {F6 30 98 07}, {A8 8D A2 34}} ;

Thank you very much,
Sep 4 '06 #1
5 4930
Banfa
9,065 Expert Mod 8TB
just use a 2 dimensional byte array (with a dimension size of 4 in both directions) and read the data directly into it. There are no 128 bit built in data types on most PC based systems.

char matrix[4][4];
Sep 4 '06 #2
Well, the thing is that the user must enter this variable (128 bits), so I must ask for this variable, I then I need to store it somehow, and create the matix, so it would be somthing like this:

cout << "Please enter the Key Number:"; //this is 128 bits
cin >> ????????????? // So how can I get this

and then I must create the matrix as I have described previous post. Thanks
Sep 4 '06 #3
D_C
293 100+
Use a string, then start chopping the string in half. Then start converting the ASCII values to characters.

For example, string 0A is 0x3061. However, you want it to be equal to 0x0A. The conversion isn't too bad.

For each character, convert it to lowercase. Then check that character c is a digit (0 <= c-'0' <= 9-0) or alphabetic (0 <= c-'a' <= 'f'-'a'). If the character is a digit, subtract '0' from it's value. If it's alphabetic, subtract ('a'-10) from it, since A is 10 in hexadecimal.

However, two characters will be stored into one character location, because 0-F can be stored with 4 bits, and a character is 8 bits. In that case, multiply the first character by 16 (1<<4) to shift it left four bits. Then simply add in the second character's value.
Sep 4 '06 #4
Could you please help me to put that in code, so I can understant how to do it. thanks.
Sep 7 '06 #5
D_C
293 100+
Actually, Banfa's way is much easier, and I think I may have been a little side tracked in my response.
Expand|Select|Wrap|Line Numbers
  1. char data[4][4];
  2. char ch;
  3. int count;
  4. for(count = 0; count < 16; count++)
  5. {
  6.   cin >> ch;
  7.   data[count%4][count/4] = ch;
  8. }
Sep 11 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
7
by: KantKwitDansin1 | last post by:
I have a file "a.dat" containing 10^4 32 bit binary numbers. I need to read in these numbers and deterimine if they are prime. The primality part I will have to figure out later, but I was...
6
by: Arjen | last post by:
Hi, I can read in a file with the binaryreader. But how can I get all the bits ("1" and "0") inside my textbox? (I now get the number 68) Thanks!
17
by: henrytcy | last post by:
Hi, How can I get a digit from integer for example, 12311, one by one for comparision? Thanks!
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
18
by: gregpinero | last post by:
It seems like this would be easy but I'm drawing a blank. What I want to do is be able to open any file in binary mode, and read in one byte (8 bits) at a time and then count the number of 1 bits...
2
by: duylam76 | last post by:
I'm programming a server and corresponding client application that sends data to each other over a socket. I want to encode an integer to send over the socket. Right now everything is fine because...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.